mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #10112 from cpuguy83/4393_fix_volume_where_file_exists
Error out if file in container at volume path
This commit is contained in:
commit
b0ed2da441
2 changed files with 23 additions and 0 deletions
|
@ -188,6 +188,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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue