diff --git a/api/client/build.go b/api/client/build.go index 79b5e76c66..38ade49ef7 100644 --- a/api/client/build.go +++ b/api/client/build.go @@ -584,7 +584,7 @@ func rewriteDockerfileFrom(dockerfileName string, translator func(reference.Name line := scanner.Text() matches := dockerfileFromLinePattern.FindStringSubmatch(line) - if matches != nil && matches[1] != "scratch" { + if matches != nil && matches[1] != api.NoBaseImageSpecifier { // Replace the line with a resolved "FROM repo@digest" ref, err := reference.ParseNamed(matches[1]) if err != nil { diff --git a/api/common.go b/api/common.go index b72070b965..ca7f0dc869 100644 --- a/api/common.go +++ b/api/common.go @@ -25,6 +25,10 @@ const ( // DefaultDockerfileName is the Default filename with Docker commands, read by docker build DefaultDockerfileName string = "Dockerfile" + + // NoBaseImageSpecifier is the symbol used by the FROM + // command to specify that no base image is to be used. + NoBaseImageSpecifier string = "scratch" ) // byPortInfo is a temporary type used to sort types.Port by its fields diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index feb91ccf76..c036cf74fb 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -17,6 +17,7 @@ import ( "strings" "github.com/Sirupsen/logrus" + "github.com/docker/docker/api" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/builder" @@ -27,12 +28,6 @@ import ( "github.com/docker/go-connections/nat" ) -const ( - // NoBaseImageSpecifier is the symbol used by the FROM - // command to specify that no base image is to be used. - NoBaseImageSpecifier string = "scratch" -) - // dispatch with no layer / parsing. This is effectively not a command. func nullDispatch(b *Builder, args []string, attributes map[string]bool, original string) error { return nil @@ -199,7 +194,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string name := args[0] // Windows cannot support a container with no base image. - if name == NoBaseImageSpecifier { + if name == api.NoBaseImageSpecifier { if runtime.GOOS == "windows" { return fmt.Errorf("Windows does not support FROM scratch") } diff --git a/distribution/pull.go b/distribution/pull.go index 0466ed6146..e367f2d272 100644 --- a/distribution/pull.go +++ b/distribution/pull.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Sirupsen/logrus" + "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/daemon/events" "github.com/docker/docker/distribution/metadata" @@ -191,8 +192,8 @@ func validateRepoName(name string) error { if name == "" { return fmt.Errorf("Repository name can't be empty") } - if name == "scratch" { - return fmt.Errorf("'scratch' is a reserved name") + if name == api.NoBaseImageSpecifier { + return fmt.Errorf("'%s' is a reserved name", api.NoBaseImageSpecifier) } return nil }