Skip to content

Commit

Permalink
Error out if file in container at volume path
Browse files Browse the repository at this point in the history
Fixes moby#4393

Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Feb 6, 2015
1 parent c2f82bb commit c73e3bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions daemon/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ func (container *Container) parseVolumeMountConfig() (map[string]*Mount, error)
continue
}

if stat, err := os.Stat(filepath.Join(container.basefs, path)); err == nil {
if !stat.IsDir() {
return nil, fmt.Errorf("file exists at %s, can't create volume there")
}
}

vol, err := container.daemon.volumes.FindOrCreateVolume("", true)
if err != nil {
return nil, err
Expand Down
17 changes: 17 additions & 0 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4784,3 +4784,20 @@ RUN echo " \

logDone("build - test spaces with quotes")
}

// #4393
func TestBuildVolumeFileExistsinContainer(t *testing.T) {
buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-errcreatevolumewithfile", "-")
buildCmd.Stdin = strings.NewReader(`
FROM busybox
RUN touch /foo
VOLUME /foo
`)

out, _, err := runCommandWithOutput(buildCmd)
if err == nil || !strings.Contains(out, "file exists") {
t.Fatalf("expected build to fail when file exists in container at requested volume path")
}

logDone("build - errors when volume is specified where a file exists")
}

0 comments on commit c73e3bf

Please sign in to comment.