mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
commit
d7bcc099be
4 changed files with 54 additions and 9 deletions
|
@ -137,6 +137,11 @@ func (container *Container) parseVolumeMountConfig() (map[string]*Mount, error)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this has already been created
|
||||||
|
if _, exists := container.Volumes[path]; exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
vol, err := container.daemon.volumes.FindOrCreateVolume("", true)
|
vol, err := container.daemon.volumes.FindOrCreateVolume("", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -2339,3 +2339,40 @@ func TestVolumesNoCopyData(t *testing.T) {
|
||||||
|
|
||||||
logDone("run - volumes do not copy data for volumes-from and bindmounts")
|
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")
|
||||||
|
}
|
||||||
|
|
|
@ -6,18 +6,21 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// the docker binary to use
|
var (
|
||||||
var dockerBinary = "docker"
|
// the docker binary to use
|
||||||
|
dockerBinary = "docker"
|
||||||
|
|
||||||
// the private registry image to use for tests involving the registry
|
// the private registry image to use for tests involving the registry
|
||||||
var registryImageName = "registry"
|
registryImageName = "registry"
|
||||||
|
|
||||||
// the private registry to use for tests
|
// the private registry to use for tests
|
||||||
var privateRegistryURL = "127.0.0.1:5000"
|
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() {
|
func init() {
|
||||||
if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
|
if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
|
||||||
|
|
|
@ -267,7 +267,7 @@ func deleteContainer(container string) error {
|
||||||
killSplitArgs := strings.Split(killArgs, " ")
|
killSplitArgs := strings.Split(killArgs, " ")
|
||||||
killCmd := exec.Command(dockerBinary, killSplitArgs...)
|
killCmd := exec.Command(dockerBinary, killSplitArgs...)
|
||||||
runCommand(killCmd)
|
runCommand(killCmd)
|
||||||
rmArgs := fmt.Sprintf("rm %v", container)
|
rmArgs := fmt.Sprintf("rm -v %v", container)
|
||||||
rmSplitArgs := strings.Split(rmArgs, " ")
|
rmSplitArgs := strings.Split(rmArgs, " ")
|
||||||
rmCmd := exec.Command(dockerBinary, rmSplitArgs...)
|
rmCmd := exec.Command(dockerBinary, rmSplitArgs...)
|
||||||
exitCode, err := runCommand(rmCmd)
|
exitCode, err := runCommand(rmCmd)
|
||||||
|
|
Loading…
Reference in a new issue