{"id":"33ef021411ec2cb3","repo":"docker/cli","slug":"invalid-argument-can-t-use-stdin-for-both-build-c","errorCode":null,"errorMessage":"invalid argument: can't use stdin for both build context and dockerfile","messagePattern":"invalid argument: can't use stdin for both build context and dockerfile","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/image/build.go","lineNumber":210,"sourceCode":"\t\tbuildBuff     io.Writer\n\t\tremote        string\n\t)\n\n\tif options.platform != \"\" {\n\t\t_, err := platforms.Parse(options.platform)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tcontextType, err := build.DetectContextType(options.context)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif options.dockerfileFromStdin() {\n\t\tif contextType == build.ContextTypeStdin {\n\t\t\treturn errors.New(\"invalid argument: can't use stdin for both build context and dockerfile\")\n\t\t}\n\t\tdockerfileCtx = dockerCli.In()\n\t}\n\n\tprogBuff = dockerCli.Out()\n\tbuildBuff = dockerCli.Out()\n\tif options.quiet {\n\t\tprogBuff = bytes.NewBuffer(nil)\n\t\tbuildBuff = bytes.NewBuffer(nil)\n\t}\n\tif options.imageIDFile != \"\" {\n\t\t// Avoid leaving a stale file if we eventually fail\n\t\tif err := os.Remove(options.imageIDFile); err != nil && !os.IsNotExist(err) {\n\t\t\treturn fmt.Errorf(\"removing image ID file: %w\", err)\n\t\t}\n\t}\n\n\tswitch contextType {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/image/build.go#L192-L228","documentation":"docker build reads the build context and optionally the Dockerfile from stdin, but stdin is a single stream and cannot serve both. This check fires when the Dockerfile flag is '-' (options.dockerfileFromStdin()) while the build context argument was also detected as stdin (build.ContextTypeStdin, i.e. the PATH argument is '-'). Allowing both would make the CLI consume the same stream twice, so it is rejected up front as an invalid argument.","triggerScenarios":"`docker build -f - -` or equivalents: build context PATH given as '-' combined with `--file -` (or -f -). Also hit when a script pipes a tar context on stdin and separately sets DOCKERFILE input to '-'.","commonSituations":"CI pipelines that pipe a tarred context (`tar c . | docker build -`) while a shared wrapper adds `-f -` to inject a generated Dockerfile; copy-pasted one-liners like `cat Dockerfile | docker build -f - -`; Makefiles composing flags from variables where both default to '-'.","solutions":["Pick one stdin use: pipe only the Dockerfile with a directory context: `docker build -f - . < Dockerfile`.","Or pipe only the context and include the Dockerfile inside it: `tar c . | docker build -` (the tar must contain the Dockerfile).","If the Dockerfile is generated, write it to a temp file and pass `-f /tmp/Dockerfile.gen .` instead of '-'."],"exampleFix":"# before\ncat Dockerfile | docker build -f - -\n# after\ncat Dockerfile | docker build -f - .","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","build","stdin","invalid-argument"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}