From 7c70ad058f89701510ddbb9d9c5ed66d42626208 Mon Sep 17 00:00:00 2001 From: Stephen Rust Date: Fri, 8 Jan 2016 13:19:25 -0500 Subject: [PATCH] Allow external volume drivers to host anonymous volumes and copy existing data from image. Signed-off-by: Stephen Rust --- daemon/create.go | 2 +- daemon/create_unix.go | 16 ++--------- daemon/create_windows.go | 11 +------- ...ocker_cli_start_volume_driver_unix_test.go | 27 ------------------- 4 files changed, 4 insertions(+), 52 deletions(-) diff --git a/daemon/create.go b/daemon/create.go index 148f2b7a88..83e1174d7d 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -105,7 +105,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig) (retC *containe } }() - if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig, img); err != nil { + if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig); err != nil { return nil, err } diff --git a/daemon/create_unix.go b/daemon/create_unix.go index 1701fcfb5b..383b3c73a4 100644 --- a/daemon/create_unix.go +++ b/daemon/create_unix.go @@ -9,15 +9,13 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/container" derr "github.com/docker/docker/errors" - "github.com/docker/docker/image" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/volume" containertypes "github.com/docker/engine-api/types/container" "github.com/opencontainers/runc/libcontainer/label" ) // createContainerPlatformSpecificSettings performs platform specific container create functionality -func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig, img *image.Image) error { +func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error { if err := daemon.Mount(container); err != nil { return err } @@ -42,17 +40,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain return derr.ErrorCodeMountOverFile.WithArgs(path) } - volumeDriver := hostConfig.VolumeDriver - if destination != "" && img != nil { - if _, ok := img.ContainerConfig.Volumes[destination]; ok { - // check for whether bind is not specified and then set to local - if _, ok := container.MountPoints[destination]; !ok { - volumeDriver = volume.DefaultDriverName - } - } - } - - v, err := daemon.volumes.CreateWithRef(name, volumeDriver, container.ID, nil) + v, err := daemon.volumes.CreateWithRef(name, hostConfig.VolumeDriver, container.ID, nil) if err != nil { return err } diff --git a/daemon/create_windows.go b/daemon/create_windows.go index 54b0ab6ab7..d8fc059fd3 100644 --- a/daemon/create_windows.go +++ b/daemon/create_windows.go @@ -4,14 +4,13 @@ import ( "fmt" "github.com/docker/docker/container" - "github.com/docker/docker/image" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/volume" containertypes "github.com/docker/engine-api/types/container" ) // createContainerPlatformSpecificSettings performs platform specific container create functionality -func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig, img *image.Image) error { +func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error { for spec := range config.Volumes { mp, err := volume.ParseMountSpec(spec, hostConfig.VolumeDriver) @@ -31,14 +30,6 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain } volumeDriver := hostConfig.VolumeDriver - if mp.Destination != "" && img != nil { - if _, ok := img.ContainerConfig.Volumes[mp.Destination]; ok { - // check for whether bind is not specified and then set to local - if _, ok := container.MountPoints[mp.Destination]; !ok { - volumeDriver = volume.DefaultDriverName - } - } - } // Create the volume in the volume driver. If it doesn't exist, // a new one will be created. diff --git a/integration-cli/docker_cli_start_volume_driver_unix_test.go b/integration-cli/docker_cli_start_volume_driver_unix_test.go index a8ad58f233..28c1c77717 100644 --- a/integration-cli/docker_cli_start_volume_driver_unix_test.go +++ b/integration-cli/docker_cli_start_volume_driver_unix_test.go @@ -296,33 +296,6 @@ func hostVolumePath(name string) string { return fmt.Sprintf("/var/lib/docker/volumes/%s", name) } -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamedCheckBindLocalVolume(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - expected := s.server.URL - dockerfile := fmt.Sprintf(`FROM busybox:latest - RUN mkdir /nobindthenlocalvol - RUN echo %s > /nobindthenlocalvol/test - VOLUME ["/nobindthenlocalvol"]`, expected) - - img := "test-checkbindlocalvolume" - - _, err = buildImageWithOutInDamon(s.d.sock(), img, dockerfile, true) - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "--rm", "--name", "test-data-nobind", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver", img, "cat", "/nobindthenlocalvol/test") - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Contains, expected) - - c.Assert(s.ec.activations, checker.Equals, 1) - c.Assert(s.ec.creations, checker.Equals, 1) - c.Assert(s.ec.removals, checker.Equals, 1) - c.Assert(s.ec.mounts, checker.Equals, 1) - c.Assert(s.ec.unmounts, checker.Equals, 1) -} - // Make sure a request to use a down driver doesn't block other requests func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) { specPath := "/etc/docker/plugins/down-driver.spec"