{"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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/start.go#L68-L104","documentation":"Raised in RunStart for `docker start` when attach mode is requested (--attach/-a or --interactive/-i) with more than one container argument. Attaching hijacks a single bidirectional stream to one container's stdio and wires up TTY/signal forwarding, which cannot be multiplexed across containers, so the CLI enforces exactly one container in this mode.","triggerScenarios":"`docker start -a ctr1 ctr2`, `docker start -i ctr1 ctr2 ctr3` — opts.Attach or opts.OpenStdin true with len(opts.Containers) > 1. Without -a/-i, starting multiple containers at once is fine.","commonSituations":"Scripts that expand a list of containers into `docker start -a $list`; users adding -a out of habit when bulk-restarting stopped containers; confusion with docker-compose which can stream logs from many services at once.","solutions":["Drop -a/-i to start all containers detached: docker start ctr1 ctr2, then follow one with docker logs -f","Start and attach to just one container per command: docker start -a ctr1","To watch output of several containers, start them detached and use docker logs -f per container (or docker compose up)"],"exampleFix":"# before\ndocker start -a web db cache\n# after\ndocker start web db cache\ndocker logs -f web","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","container","start","attach","argument-validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}