docker/cli · error
conflicting options: cannot specify both --attach and --deta
Error message
conflicting options: cannot specify both --attach and --detach
What it means
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.
Source
Thrown at cli/command/container/run.go:134
}
return runContainer(ctx, dockerCLI, ropts, copts, containerCfg)
}
//nolint:gocyclo
func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOptions, copts *containerOptions, containerCfg *containerConfig) error {
config := containerCfg.Config
stdout, stderr := dockerCli.Out(), dockerCli.Err()
apiClient := dockerCli.Client()
config.ArgsEscaped = false
if !runOpts.detach {
if err := dockerCli.In().CheckTty(config.AttachStdin, config.Tty); err != nil {
return err
}
} else {
if copts.attach.Len() != 0 {
return errors.New("conflicting options: cannot specify both --attach and --detach")
}
config.AttachStdin = false
config.AttachStdout = false
config.AttachStderr = false
config.StdinOnce = false
}
detachKeys := runOpts.detachKeys
if detachKeys == "" {
detachKeys = dockerCli.ConfigFile().DetachKeys
}
if err := validateDetachKeys(runOpts.detachKeys); err != nil {
return err
}
containerID, err := createContainer(ctx, dockerCli, containerCfg, &runOpts.createOptions)
if err != nil {View on GitHub (pinned to e9452d6e78)
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>
Example fix
# before docker run -d -a stdout myimage # after docker run -d myimage && docker logs -f $(docker ps -lq)
When it happens
Trigger: `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.)
Common situations: 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`.
Related errors
- conflicting options: cannot specify both --timeout and --tim
- filtering is not supported when specifying a list of contain
- conflicting options: cannot specify both --network-alias and
- valid streams are STDIN, STDOUT and STDERR
- container prune has been cancelled
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/fe47b92bf94898f1.json.
Report an issue: GitHub.