Merge pull request #8475 from cpuguy83/fix_create_phantom_volumes_on_container_restart

Fixes re-creating volume on (re)start
This commit is contained in:
Andrea Luzzardi 2014-10-08 13:58:56 -07:00
commit d7bcc099be
4 changed files with 54 additions and 9 deletions

View file

@ -137,6 +137,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

View file

@ -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")
}

View file

@ -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 != "" {

View file

@ -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)