2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-07-16 21:14:58 +00:00
|
|
|
|
|
|
|
import (
|
2018-03-22 21:11:03 +00:00
|
|
|
"context"
|
2015-09-10 02:23:06 +00:00
|
|
|
"fmt"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2015-11-12 19:55:17 +00:00
|
|
|
"github.com/docker/docker/container"
|
2018-04-17 20:50:28 +00:00
|
|
|
volumemounts "github.com/docker/docker/volume/mounts"
|
2018-03-22 21:11:03 +00:00
|
|
|
volumeopts "github.com/docker/docker/volume/service/opts"
|
2015-07-16 21:14:58 +00:00
|
|
|
)
|
|
|
|
|
2017-08-08 19:43:48 +00:00
|
|
|
// createContainerOSSpecificSettings performs host-OS specific container create functionality
|
2023-07-27 12:56:28 +00:00
|
|
|
func (daemon *Daemon) createContainerOSSpecificSettings(ctx context.Context, container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
|
2021-07-27 10:12:11 +00:00
|
|
|
if containertypes.Isolation.IsDefault(hostConfig.Isolation) {
|
2017-08-09 16:00:05 +00:00
|
|
|
// Make sure the host config has the default daemon isolation if not specified by caller.
|
2021-07-27 10:12:11 +00:00
|
|
|
hostConfig.Isolation = daemon.defaultIsolation
|
2016-05-26 20:24:22 +00:00
|
|
|
}
|
2021-06-11 19:01:18 +00:00
|
|
|
parser := volumemounts.NewParser()
|
2015-09-10 02:23:06 +00:00
|
|
|
for spec := range config.Volumes {
|
|
|
|
|
2017-08-01 17:32:44 +00:00
|
|
|
mp, err := parser.ParseMountRaw(spec, hostConfig.VolumeDriver)
|
2015-09-10 02:23:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Unrecognised volume spec: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip volumes for which we already have something mounted on that
|
|
|
|
// destination because of a --volume-from.
|
2015-11-12 19:55:17 +00:00
|
|
|
if container.IsDestinationMounted(mp.Destination) {
|
2015-09-10 02:23:06 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
volumeDriver := hostConfig.VolumeDriver
|
|
|
|
|
|
|
|
// Create the volume in the volume driver. If it doesn't exist,
|
|
|
|
// a new one will be created.
|
2023-07-27 12:56:28 +00:00
|
|
|
v, err := daemon.volumes.Create(ctx, "", volumeDriver, volumeopts.WithCreateReference(container.ID))
|
2015-09-10 02:23:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME Windows: This code block is present in the Linux version and
|
|
|
|
// allows the contents to be copied to the container FS prior to it
|
2015-12-13 16:00:39 +00:00
|
|
|
// being started. However, the function utilizes the FollowSymLinkInScope
|
2015-09-10 02:23:06 +00:00
|
|
|
// path which does not cope with Windows volume-style file paths. There
|
2015-12-13 16:00:39 +00:00
|
|
|
// is a separate effort to resolve this (@swernli), so this processing
|
2015-09-10 02:23:06 +00:00
|
|
|
// is deferred for now. A case where this would be useful is when
|
|
|
|
// a dockerfile includes a VOLUME statement, but something is created
|
|
|
|
// in that directory during the dockerfile processing. What this means
|
2016-04-06 19:01:29 +00:00
|
|
|
// on Windows for TP5 is that in that scenario, the contents will not
|
2015-09-10 02:23:06 +00:00
|
|
|
// copied, but that's (somewhat) OK as HCS will bomb out soon after
|
|
|
|
// at it doesn't support mapped directories which have contents in the
|
|
|
|
// destination path anyway.
|
|
|
|
//
|
|
|
|
// Example for repro later:
|
|
|
|
// FROM windowsservercore
|
|
|
|
// RUN mkdir c:\myvol
|
|
|
|
// RUN copy c:\windows\system32\ntdll.dll c:\myvol
|
|
|
|
// VOLUME "c:\myvol"
|
|
|
|
//
|
|
|
|
// Then
|
|
|
|
// docker build -t vol .
|
|
|
|
// docker run -it --rm vol cmd <-- This is where HCS will error out.
|
|
|
|
//
|
|
|
|
// // never attempt to copy existing content in a container FS to a shared volume
|
|
|
|
// if v.DriverName() == volume.DefaultDriverName {
|
2015-11-12 19:55:17 +00:00
|
|
|
// if err := container.CopyImagePathContent(v, mp.Destination); err != nil {
|
2015-09-10 02:23:06 +00:00
|
|
|
// return err
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Add it to container.MountPoints
|
2018-03-22 21:11:03 +00:00
|
|
|
container.AddMountPointWithVolume(mp.Destination, &volumeWrapper{v: v, s: daemon.volumes}, mp.RW)
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
2015-07-16 21:14:58 +00:00
|
|
|
return nil
|
|
|
|
}
|