diff --git a/daemon/create_unix.go b/daemon/create_unix.go index b8db2bc997..66138db967 100644 --- a/daemon/create_unix.go +++ b/daemon/create_unix.go @@ -5,7 +5,6 @@ package daemon import ( "os" "path/filepath" - "strings" derr "github.com/docker/docker/errors" "github.com/docker/docker/image" @@ -18,17 +17,9 @@ import ( // createContainerPlatformSpecificSettings performs platform specific container create functionality func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error { for spec := range config.Volumes { - var ( - name, destination string - parts = strings.Split(spec, ":") - ) - switch len(parts) { - case 2: - name, destination = parts[0], filepath.Clean(parts[1]) - default: - name = stringid.GenerateNonCryptoID() - destination = filepath.Clean(parts[0]) - } + name := stringid.GenerateNonCryptoID() + destination := filepath.Clean(spec) + // Skip volumes for which we already have something mounted on that // destination because of a --volume-from. if container.isDestinationMounted(destination) { diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 0d721e48c2..b7a166aad1 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5641,7 +5641,7 @@ func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) { ctx, err := fakeContext(` FROM busybox - + ADD null / COPY nullfile / VOLUME nullvolume @@ -6194,3 +6194,15 @@ func (s *DockerSuite) TestBuildBuildTimeArgDefintionWithNoEnvInjection(c *check. c.Fatalf("unexpected number of occurrences of the arg in output: %q expected: 1", out) } } + +func (s *DockerSuite) TestBuildNoNamedVolume(c *check.C) { + testRequires(c, DaemonIsLinux) + dockerCmd(c, "run", "-v", "testname:/foo", "busybox", "sh", "-c", "touch /foo/oops") + + dockerFile := `FROM busybox + VOLUME testname:/foo + RUN ls /foo/oops + ` + _, err := buildImage("test", dockerFile, false) + c.Assert(err, check.NotNil, check.Commentf("image build should have failed")) +}