From 39be36658d559d0fe28c902ad0f45287868c7ebb Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Tue, 1 Sep 2015 20:13:38 -0400 Subject: [PATCH] Set bind driver after volume is created When using a named volume without --volume-driver, the driver was hardcoded to "local". Even when the volume was already created by some other driver (and visible in `docker volume ls`), the container would store in it's own config that it was the `local` driver. The external driver would work perfecly fine until the daemon is restarted, at which point the `local` driver was assumed because that is as it was set in the container config. Set the bind driver to the driver returned by createVolume. Signed-off-by: Brian Goff --- daemon/create_unix.go | 2 +- daemon/volumes_unix.go | 2 ++ .../docker_cli_start_volume_driver_unix_test.go | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/daemon/create_unix.go b/daemon/create_unix.go index b6a0edb202..90491030c0 100644 --- a/daemon/create_unix.go +++ b/daemon/create_unix.go @@ -64,7 +64,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco } // never attempt to copy existing content in a container FS to a shared volume - if volumeDriver == volume.DefaultDriverName || volumeDriver == "" { + if v.DriverName() == volume.DefaultDriverName { if err := container.copyImagePathContent(v, destination); err != nil { return err } diff --git a/daemon/volumes_unix.go b/daemon/volumes_unix.go index 0afe20ba06..7c023b01d8 100644 --- a/daemon/volumes_unix.go +++ b/daemon/volumes_unix.go @@ -342,6 +342,8 @@ func (daemon *Daemon) registerMountPoints(container *Container, hostConfig *runc } bind.Volume = v bind.Source = v.Path() + // bind.Name is an already existing volume, we need to use that here + bind.Driver = v.DriverName() // Since this is just a named volume and not a typical bind, set to shared mode `z` if bind.Mode == "" { bind.Mode = "z" 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 d2dae6a15a..2b1cd83ed3 100644 --- a/integration-cli/docker_cli_start_volume_driver_unix_test.go +++ b/integration-cli/docker_cli_start_volume_driver_unix_test.go @@ -350,3 +350,19 @@ func (s *DockerExternalVolumeSuite) TestStartExternalVolumeDriverRetryNotImmedia c.Assert(s.ec.mounts, check.Equals, 1) c.Assert(s.ec.unmounts, check.Equals, 1) } + +func (s *DockerExternalVolumeSuite) TestStartExternalVolumeDriverBindExternalVolume(c *check.C) { + dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "foo") + dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top") + + var mounts []struct { + Name string + Driver string + } + out, err := inspectFieldJSON("testing", "Mounts") + c.Assert(err, check.IsNil) + c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), check.IsNil) + c.Assert(len(mounts), check.Equals, 1, check.Commentf(out)) + c.Assert(mounts[0].Name, check.Equals, "foo") + c.Assert(mounts[0].Driver, check.Equals, "test-external-volume-driver") +}