diff --git a/daemon/volumes.go b/daemon/volumes.go index b9d622990d..629e6689d5 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -131,6 +131,11 @@ func (container *Container) parseVolumeMountConfig() (map[string]*Mount, error) continue } + // Check if this has already been created + if _, exists := container.Volumes[path]; exists { + continue + } + vol, err := container.daemon.volumes.FindOrCreateVolume("", true) if err != nil { return nil, err diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 2fd545af8d..3e11de96f6 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2339,3 +2339,40 @@ func TestVolumesNoCopyData(t *testing.T) { logDone("run - volumes do not copy data for volumes-from and bindmounts") } + +func TestRunVolumesNotRecreatedOnStart(t *testing.T) { + // Clear out any remnants from other tests + deleteAllContainers() + info, err := ioutil.ReadDir(volumesConfigPath) + if err != nil { + t.Fatal(err) + } + if len(info) > 0 { + for _, f := range info { + if err := os.RemoveAll(volumesConfigPath + "/" + f.Name()); err != nil { + t.Fatal(err) + } + } + } + + defer deleteAllContainers() + cmd := exec.Command(dockerBinary, "run", "-v", "/foo", "--name", "lone_starr", "busybox") + if _, err := runCommand(cmd); err != nil { + t.Fatal(err) + } + + cmd = exec.Command(dockerBinary, "start", "lone_starr") + if _, err := runCommand(cmd); err != nil { + t.Fatal(err) + } + + info, err = ioutil.ReadDir(volumesConfigPath) + if err != nil { + t.Fatal(err) + } + if len(info) != 1 { + t.Fatalf("Expected only 1 volume have %v", len(info)) + } + + logDone("run - volumes not recreated on start") +} diff --git a/integration-cli/docker_test_vars.go b/integration-cli/docker_test_vars.go index 87bca92e9c..fdbcf073ec 100644 --- a/integration-cli/docker_test_vars.go +++ b/integration-cli/docker_test_vars.go @@ -6,18 +6,21 @@ import ( "os/exec" ) -// the docker binary to use -var dockerBinary = "docker" +var ( + // the docker binary to use + dockerBinary = "docker" -// the private registry image to use for tests involving the registry -var registryImageName = "registry" + // the private registry image to use for tests involving the registry + registryImageName = "registry" -// the private registry to use for tests -var privateRegistryURL = "127.0.0.1:5000" + // the private registry to use for tests + privateRegistryURL = "127.0.0.1:5000" -var execDriverPath = "/var/lib/docker/execdriver/native" + execDriverPath = "/var/lib/docker/execdriver/native" + volumesConfigPath = "/var/lib/docker/volumes" -var workingDirectory string + workingDirectory string +) func init() { if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" { diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 0b990340b8..17370eb707 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -267,7 +267,7 @@ func deleteContainer(container string) error { killSplitArgs := strings.Split(killArgs, " ") killCmd := exec.Command(dockerBinary, killSplitArgs...) runCommand(killCmd) - rmArgs := fmt.Sprintf("rm %v", container) + rmArgs := fmt.Sprintf("rm -v %v", container) rmSplitArgs := strings.Split(rmArgs, " ") rmCmd := exec.Command(dockerBinary, rmSplitArgs...) exitCode, err := runCommand(rmCmd)