mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Merge pull request #10365 from cpuguy83/9981_fix_cannot_overwrite_nonbind_as_bind
Allow path from normal volume existing to overwrite in start Binds
This commit is contained in:
@ -516,3 +516,40 @@ func TestBuildApiDockerfileSymlink(t *testing.T) {
|
||||
|
||||
logDone("container REST API - check build w/bad Dockerfile symlink path")
|
||||
}
|
||||
|
||||
// #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume
|
||||
func TestPostContainerBindNormalVolume(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=one", "busybox"))
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
fooDir, err := inspectFieldMap("one", "Volumes", "/foo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=two", "busybox"))
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
||||
_, err = sockRequest("POST", "/containers/two/start", bindSpec)
|
||||
if err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fooDir2, err := inspectFieldMap("two", "Volumes", "/foo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if fooDir2 != fooDir {
|
||||
t.Fatal("expected volume path to be %s, got: %s", fooDir, fooDir2)
|
||||
}
|
||||
|
||||
logDone("container REST API - can use path from normal volume as bind-mount to overwrite another volume")
|
||||
}
|
||||
|
Reference in New Issue
Block a user