Browse code

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 <cpuguy83@gmail.com>

Brian Goff authored on 2015/09/02 09:13:38
Showing 3 changed files
... ...
@@ -64,7 +64,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
64 64
 		}
65 65
 
66 66
 		// never attempt to copy existing content in a container FS to a shared volume
67
-		if volumeDriver == volume.DefaultDriverName || volumeDriver == "" {
67
+		if v.DriverName() == volume.DefaultDriverName {
68 68
 			if err := container.copyImagePathContent(v, destination); err != nil {
69 69
 				return err
70 70
 			}
... ...
@@ -342,6 +342,8 @@ func (daemon *Daemon) registerMountPoints(container *Container, hostConfig *runc
342 342
 			}
343 343
 			bind.Volume = v
344 344
 			bind.Source = v.Path()
345
+			// bind.Name is an already existing volume, we need to use that here
346
+			bind.Driver = v.DriverName()
345 347
 			// Since this is just a named volume and not a typical bind, set to shared mode `z`
346 348
 			if bind.Mode == "" {
347 349
 				bind.Mode = "z"
... ...
@@ -350,3 +350,19 @@ func (s *DockerExternalVolumeSuite) TestStartExternalVolumeDriverRetryNotImmedia
350 350
 	c.Assert(s.ec.mounts, check.Equals, 1)
351 351
 	c.Assert(s.ec.unmounts, check.Equals, 1)
352 352
 }
353
+
354
+func (s *DockerExternalVolumeSuite) TestStartExternalVolumeDriverBindExternalVolume(c *check.C) {
355
+	dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "foo")
356
+	dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top")
357
+
358
+	var mounts []struct {
359
+		Name   string
360
+		Driver string
361
+	}
362
+	out, err := inspectFieldJSON("testing", "Mounts")
363
+	c.Assert(err, check.IsNil)
364
+	c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), check.IsNil)
365
+	c.Assert(len(mounts), check.Equals, 1, check.Commentf(out))
366
+	c.Assert(mounts[0].Name, check.Equals, "foo")
367
+	c.Assert(mounts[0].Driver, check.Equals, "test-external-volume-driver")
368
+}