Fixes #5244
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,27 @@ |
0 |
+package main |
|
1 |
+ |
|
2 |
+import ( |
|
3 |
+ "os" |
|
4 |
+ "os/exec" |
|
5 |
+ "testing" |
|
6 |
+) |
|
7 |
+ |
|
8 |
+func TestRemoveContainerWithRemovedVolume(t *testing.T) { |
|
9 |
+ cmd := exec.Command(dockerBinary, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true") |
|
10 |
+ if _, err := runCommand(cmd); err != nil { |
|
11 |
+ t.Fatal(err) |
|
12 |
+ } |
|
13 |
+ |
|
14 |
+ if err := os.Remove("/tmp/testing"); err != nil { |
|
15 |
+ t.Fatal(err) |
|
16 |
+ } |
|
17 |
+ |
|
18 |
+ cmd = exec.Command(dockerBinary, "rm", "-v", "losemyvolumes") |
|
19 |
+ if _, err := runCommand(cmd); err != nil { |
|
20 |
+ t.Fatal(err) |
|
21 |
+ } |
|
22 |
+ |
|
23 |
+ deleteAllContainers() |
|
24 |
+ |
|
25 |
+ logDone("rm - removed volume") |
|
26 |
+} |
... | ... |
@@ -1867,13 +1867,16 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status { |
1867 | 1867 |
for _, bind := range container.HostConfig().Binds { |
1868 | 1868 |
source := strings.Split(bind, ":")[0] |
1869 | 1869 |
// TODO: refactor all volume stuff, all of it |
1870 |
- // this is very important that we eval the link |
|
1871 |
- // or comparing the keys to container.Volumes will not work |
|
1870 |
+ // it is very important that we eval the link or comparing the keys to container.Volumes will not work |
|
1871 |
+ // |
|
1872 |
+ // eval symlink can fail, ref #5244 if we receive an is not exist error we can ignore it |
|
1872 | 1873 |
p, err := filepath.EvalSymlinks(source) |
1873 |
- if err != nil { |
|
1874 |
+ if err != nil && !os.IsNotExist(err) { |
|
1874 | 1875 |
return job.Error(err) |
1875 | 1876 |
} |
1876 |
- source = p |
|
1877 |
+ if p != "" { |
|
1878 |
+ source = p |
|
1879 |
+ } |
|
1877 | 1880 |
binds[source] = struct{}{} |
1878 | 1881 |
} |
1879 | 1882 |
|