diff --git a/cli/command/image/build.go b/cli/command/image/build.go index b8dd40894e..a329378350 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -35,6 +35,8 @@ import ( "github.com/spf13/cobra" ) +var errStdinConflict = errors.New("invalid argument: can't use stdin for both build context and dockerfile") + type buildOptions struct { context string dockerfileName string @@ -192,7 +194,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error { if options.dockerfileFromStdin() { if options.contextFromStdin() { - return errors.New("invalid argument: can't use stdin for both build context and dockerfile") + return errStdinConflict } dockerfileCtx = dockerCli.In() } diff --git a/cli/command/image/build_buildkit.go b/cli/command/image/build_buildkit.go index 808d05c90b..d678d78a3c 100644 --- a/cli/command/image/build_buildkit.go +++ b/cli/command/image/build_buildkit.go @@ -51,6 +51,9 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error { ) switch { case options.contextFromStdin(): + if options.dockerfileFromStdin() { + return errStdinConflict + } rc, isArchive, err := build.DetectArchiveReader(os.Stdin) if err != nil { return err