docker/cli · error

you cannot start and attach multiple containers at once

Error message

you cannot start and attach multiple containers at once

What it means

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).

Solutions

  1. Start only one container when using -a/-i: `docker start -a c1`.
  2. To start several containers without attaching, drop -a/-i: `docker start c1 c2`.
  3. To follow logs of multiple containers, start them detached and use `docker logs -f` or a log aggregator.

Example fix

// before
docker start -a c1 c2

// after
docker start c1 c2   # no attach
docker logs -f c1     # follow separately
Defensive patterns

Strategy: validation

Validate before calling

func validateStart(attach, interactive bool, containers []string) error {
    if (attach || interactive) && len(containers) > 1 {
        return errors.New("you cannot start and attach multiple containers at once")
    }
    return nil
}

Prevention

When it happens

Trigger: `docker start -a c1 c2` or `docker start -i c1 c2 c3`. Attach||OpenStdin is true and len(opts.Containers) > 1.

Common situations: 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).

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/d3b55a67dd894a34. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/container/start.go:86

//nolint:gocyclo
func RunStart(ctx context.Context, dockerCli command.Cli, opts *StartOptions) error {
	ctx, cancelFun := context.WithCancel(ctx)
	defer cancelFun()

	detachKeys := opts.DetachKeys
	if detachKeys == "" {
		detachKeys = dockerCli.ConfigFile().DetachKeys
	}
	if err := validateDetachKeys(detachKeys); err != nil {
		return err
	}

	switch {
	case opts.Attach || opts.OpenStdin:
		// We're going to attach to a container.
		// 1. Ensure we only have one container.
		if len(opts.Containers) > 1 {
			return errors.New("you cannot start and attach multiple containers at once")
		}

		// 2. Attach to the container.
		ctr := opts.Containers[0]
		c, err := dockerCli.Client().ContainerInspect(ctx, ctr, client.ContainerInspectOptions{})
		if err != nil {
			return err
		}

		// We always use c.ID instead of container to maintain consistency during `docker start`
		if !c.Container.Config.Tty {
			sigc := notifyAllSignals()
			bgCtx := context.WithoutCancel(ctx)
			go ForwardAllSignals(bgCtx, dockerCli.Client(), c.Container.ID, sigc)
			defer signal.StopCatch(sigc)
		}

		options := client.ContainerAttachOptions{

View on GitHub (pinned to 4f84911bfe)