diff --git a/command/image/build.go b/command/image/build.go index 3c92ba20b9..fe903c74ef 100644 --- a/command/image/build.go +++ b/command/image/build.go @@ -156,12 +156,14 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error { switch { case specifiedContext == "-": buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName) + case isLocalDir(specifiedContext): + contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName) case urlutil.IsGitURL(specifiedContext): tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, options.dockerfileName) case urlutil.IsURL(specifiedContext): buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName) default: - contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName) + return fmt.Errorf("unable to prepare context: path %q not found", specifiedContext) } if err != nil { @@ -356,6 +358,11 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error { return nil } +func isLocalDir(c string) bool { + _, err := os.Stat(c) + return err == nil +} + type translatorFunc func(context.Context, reference.NamedTagged) (reference.Canonical, error) // validateTag checks if the given image name can be resolved.