From 39103e72a3ca4ff739a4986c4e4849339e08aaf3 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 14 Apr 2014 12:43:01 +0000 Subject: [PATCH] Fix unmount when host volume is removed Fixes #5244 Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- integration-cli/docker_cli_rm_test.go | 27 +++++++++++++++++++++++++++ server/server.go | 11 +++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 integration-cli/docker_cli_rm_test.go diff --git a/integration-cli/docker_cli_rm_test.go b/integration-cli/docker_cli_rm_test.go new file mode 100644 index 0000000000..5b35e8fa47 --- /dev/null +++ b/integration-cli/docker_cli_rm_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "os" + "os/exec" + "testing" +) + +func TestRemoveContainerWithRemovedVolume(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true") + if _, err := runCommand(cmd); err != nil { + t.Fatal(err) + } + + if err := os.Remove("/tmp/testing"); err != nil { + t.Fatal(err) + } + + cmd = exec.Command(dockerBinary, "rm", "-v", "losemyvolumes") + if _, err := runCommand(cmd); err != nil { + t.Fatal(err) + } + + deleteAllContainers() + + logDone("rm - removed volume") +} diff --git a/server/server.go b/server/server.go index 2de7dbc872..182505a680 100644 --- a/server/server.go +++ b/server/server.go @@ -1867,13 +1867,16 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status { for _, bind := range container.HostConfig().Binds { source := strings.Split(bind, ":")[0] // TODO: refactor all volume stuff, all of it - // this is very important that we eval the link - // or comparing the keys to container.Volumes will not work + // it is very important that we eval the link or comparing the keys to container.Volumes will not work + // + // eval symlink can fail, ref #5244 if we receive an is not exist error we can ignore it p, err := filepath.EvalSymlinks(source) - if err != nil { + if err != nil && !os.IsNotExist(err) { return job.Error(err) } - source = p + if p != "" { + source = p + } binds[source] = struct{}{} }