|
@@ -13,6 +13,7 @@ import (
|
|
|
mounttypes "github.com/docker/docker/api/types/mount"
|
|
|
"github.com/docker/docker/container"
|
|
|
"github.com/docker/docker/errdefs"
|
|
|
+ "github.com/docker/docker/internal/compatcontext"
|
|
|
"github.com/docker/docker/oci"
|
|
|
volumemounts "github.com/docker/docker/volume/mounts"
|
|
|
volumeopts "github.com/docker/docker/volume/service/opts"
|
|
@@ -21,7 +22,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// createContainerOSSpecificSettings performs host-OS specific container create functionality
|
|
|
-func (daemon *Daemon) createContainerOSSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
|
|
|
+func (daemon *Daemon) createContainerOSSpecificSettings(ctx context.Context, container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
|
|
|
if err := daemon.Mount(container); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -48,7 +49,7 @@ func (daemon *Daemon) createContainerOSSpecificSettings(container *container.Con
|
|
|
// Skip volumes for which we already have something mounted on that
|
|
|
// destination because of a --volume-from.
|
|
|
if container.HasMountFor(destination) {
|
|
|
- log.G(context.TODO()).WithField("container", container.ID).WithField("destination", spec).Debug("mountpoint already exists, skipping anonymous volume")
|
|
|
+ log.G(ctx).WithField("container", container.ID).WithField("destination", spec).Debug("mountpoint already exists, skipping anonymous volume")
|
|
|
// Not an error, this could easily have come from the image config.
|
|
|
continue
|
|
|
}
|
|
@@ -73,12 +74,12 @@ func (daemon *Daemon) createContainerOSSpecificSettings(container *container.Con
|
|
|
|
|
|
container.AddMountPointWithVolume(destination, &volumeWrapper{v: v, s: daemon.volumes}, true)
|
|
|
}
|
|
|
- return daemon.populateVolumes(container)
|
|
|
+ return daemon.populateVolumes(ctx, container)
|
|
|
}
|
|
|
|
|
|
// populateVolumes copies data from the container's rootfs into the volume for non-binds.
|
|
|
// this is only called when the container is created.
|
|
|
-func (daemon *Daemon) populateVolumes(c *container.Container) error {
|
|
|
+func (daemon *Daemon) populateVolumes(ctx context.Context, c *container.Container) error {
|
|
|
for _, mnt := range c.MountPoints {
|
|
|
if mnt.Volume == nil {
|
|
|
continue
|
|
@@ -88,14 +89,14 @@ func (daemon *Daemon) populateVolumes(c *container.Container) error {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- if err := daemon.populateVolume(c, mnt); err != nil {
|
|
|
+ if err := daemon.populateVolume(ctx, c, mnt); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (daemon *Daemon) populateVolume(c *container.Container, mnt *volumemounts.MountPoint) error {
|
|
|
+func (daemon *Daemon) populateVolume(ctx context.Context, c *container.Container, mnt *volumemounts.MountPoint) error {
|
|
|
ctrDestPath, err := c.GetResourcePath(mnt.Destination)
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -108,18 +109,18 @@ func (daemon *Daemon) populateVolume(c *container.Container, mnt *volumemounts.M
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- volumePath, cleanup, err := mnt.Setup(c.MountLabel, daemon.idMapping.RootPair(), nil)
|
|
|
+ volumePath, cleanup, err := mnt.Setup(ctx, c.MountLabel, daemon.idMapping.RootPair(), nil)
|
|
|
if err != nil {
|
|
|
if errdefs.IsNotFound(err) {
|
|
|
return nil
|
|
|
}
|
|
|
- log.G(context.TODO()).WithError(err).Debugf("can't copy data from %s:%s, to %s", c.ID, mnt.Destination, volumePath)
|
|
|
+ log.G(ctx).WithError(err).Debugf("can't copy data from %s:%s, to %s", c.ID, mnt.Destination, volumePath)
|
|
|
return errors.Wrapf(err, "failed to populate volume")
|
|
|
}
|
|
|
- defer mnt.Cleanup()
|
|
|
- defer cleanup()
|
|
|
+ defer mnt.Cleanup(compatcontext.WithoutCancel(ctx))
|
|
|
+ defer cleanup(compatcontext.WithoutCancel(ctx))
|
|
|
|
|
|
- log.G(context.TODO()).Debugf("copying image data from %s:%s, to %s", c.ID, mnt.Destination, volumePath)
|
|
|
+ log.G(ctx).Debugf("copying image data from %s:%s, to %s", c.ID, mnt.Destination, volumePath)
|
|
|
if err := c.CopyImagePathContent(volumePath, ctrDestPath); err != nil {
|
|
|
return err
|
|
|
}
|