{"id":"fe47b92bf94898f1","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-attach","errorCode":null,"errorMessage":"conflicting options: cannot specify both --attach and --detach","messagePattern":"conflicting options: cannot specify both --attach and --detach","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/run.go","lineNumber":134,"sourceCode":"\t}\n\treturn runContainer(ctx, dockerCLI, ropts, copts, containerCfg)\n}\n\n//nolint:gocyclo\nfunc runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOptions, copts *containerOptions, containerCfg *containerConfig) error {\n\tconfig := containerCfg.Config\n\tstdout, stderr := dockerCli.Out(), dockerCli.Err()\n\tapiClient := dockerCli.Client()\n\n\tconfig.ArgsEscaped = false\n\n\tif !runOpts.detach {\n\t\tif err := dockerCli.In().CheckTty(config.AttachStdin, config.Tty); err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\tif copts.attach.Len() != 0 {\n\t\t\treturn errors.New(\"conflicting options: cannot specify both --attach and --detach\")\n\t\t}\n\n\t\tconfig.AttachStdin = false\n\t\tconfig.AttachStdout = false\n\t\tconfig.AttachStderr = false\n\t\tconfig.StdinOnce = false\n\t}\n\n\tdetachKeys := runOpts.detachKeys\n\tif detachKeys == \"\" {\n\t\tdetachKeys = dockerCli.ConfigFile().DetachKeys\n\t}\n\tif err := validateDetachKeys(runOpts.detachKeys); err != nil {\n\t\treturn err\n\t}\n\n\tcontainerID, err := createContainer(ctx, dockerCli, containerCfg, &runOpts.createOptions)\n\tif err != nil {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/run.go#L116-L152","documentation":"Raised in runContainer for `docker run` when --detach/-d is set together with one or more --attach/-a values. Detached mode explicitly clears all attach settings (AttachStdin/Stdout/Stderr), so requesting stream attachment at the same time is contradictory and the CLI rejects it rather than silently ignoring --attach.","triggerScenarios":"`docker run -d -a stdout image`, `docker run --detach --attach stderr image` — any run where runOpts.detach is true and copts.attach has at least one stream. (--detach with -i/--tty interactions are handled separately; this check is specifically about --attach.)","commonSituations":"Compose-like wrappers or shell aliases that always add -d colliding with manually added -a flags; copy-pasted foreground commands with -a getting -d appended for backgrounding; misunderstanding -a as 'attach later', which is actually `docker attach`.","solutions":["Drop --attach if you want a background container: docker run -d image (then use docker logs or docker attach later)","Drop --detach if you want to stream output now: docker run -a stdout -a stderr image","To background first and view output afterwards, use docker run -d ... followed by docker logs -f <ctr> or docker attach <ctr>"],"exampleFix":"# before\ndocker run -d -a stdout myimage\n# after\ndocker run -d myimage && docker logs -f $(docker ps -lq)","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","container","run","conflicting-flags","detach"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}