{"record":{"id":"d3b55a67dd894a34","repo":"docker/cli","slug":"you-cannot-start-and-attach-multiple-containers-at","errorCode":null,"errorMessage":"you cannot start and attach multiple containers at once","messagePattern":"you cannot start and attach multiple containers at once","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/start.go","lineNumber":86,"sourceCode":"//nolint:gocyclo\nfunc RunStart(ctx context.Context, dockerCli command.Cli, opts *StartOptions) error {\n\tctx, cancelFun := context.WithCancel(ctx)\n\tdefer cancelFun()\n\n\tdetachKeys := opts.DetachKeys\n\tif detachKeys == \"\" {\n\t\tdetachKeys = dockerCli.ConfigFile().DetachKeys\n\t}\n\tif err := validateDetachKeys(detachKeys); err != nil {\n\t\treturn err\n\t}\n\n\tswitch {\n\tcase opts.Attach || opts.OpenStdin:\n\t\t// We're going to attach to a container.\n\t\t// 1. Ensure we only have one container.\n\t\tif len(opts.Containers) > 1 {\n\t\t\treturn errors.New(\"you cannot start and attach multiple containers at once\")\n\t\t}\n\n\t\t// 2. Attach to the container.\n\t\tctr := opts.Containers[0]\n\t\tc, err := dockerCli.Client().ContainerInspect(ctx, ctr, client.ContainerInspectOptions{})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// We always use c.ID instead of container to maintain consistency during `docker start`\n\t\tif !c.Container.Config.Tty {\n\t\t\tsigc := notifyAllSignals()\n\t\t\tbgCtx := context.WithoutCancel(ctx)\n\t\t\tgo ForwardAllSignals(bgCtx, dockerCli.Client(), c.Container.ID, sigc)\n\t\t\tdefer signal.StopCatch(sigc)\n\t\t}\n\n\t\toptions := client.ContainerAttachOptions{","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/start.go#L68-L104","documentation":"Returned by RunStart when --attach (-a) or --interactive (-i) is used together with more than one container argument. Attaching ties the CLI to a single container's streams, so the code requires exactly one container in that branch (start.go:82-87).","triggerScenarios":"`docker start -a c1 c2` or `docker start -i c1 c2 c3`. Attach||OpenStdin is true and len(opts.Containers) > 1.","commonSituations":"Batch-starting containers with a global -i/-a flag copied from a single-container example. Scripts that always pass --attach. Wanting to follow logs of several containers at once (not supported by start).","solutions":["Start only one container when using -a/-i: `docker start -a c1`.","To start several containers without attaching, drop -a/-i: `docker start c1 c2`.","To follow logs of multiple containers, start them detached and use `docker logs -f` or a log aggregator."],"exampleFix":"// before\ndocker start -a c1 c2\n\n// after\ndocker start c1 c2   # no attach\ndocker logs -f c1     # follow separately","handlingStrategy":"validation","validationCode":"func validateStart(attach, interactive bool, containers []string) error {\n    if (attach || interactive) && len(containers) > 1 {\n        return errors.New(\"you cannot start and attach multiple containers at once\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate -a/-i on single-container invocations only.","For batch starts, drop attach flags and follow logs separately.","Parameterize your start helper to enforce the one-container rule when attaching."],"tags":["cli-options","attach","container","start"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}