docker/compose · error

cannot combine --attach and --attach-dependencies

Error message

cannot combine --attach and --attach-dependencies

What it means

In docker compose up, --attach SERVICE... restricts attached output to named services, while --attach-dependencies implicitly attaches to dependencies of the selected services; the two modes are mutually exclusive. The RunE in cmd/compose/up.go checks len(up.attach) != 0 && up.attachDependencies after project loading and fails before runUp.

Source

Thrown at cmd/compose/up.go:135

	upCmd := &cobra.Command{
		Use:   "up [OPTIONS] [SERVICE...]",
		Short: "Create and start containers",
		PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
			create.pullChanged = cmd.Flags().Changed("pull")
			create.timeChanged = cmd.Flags().Changed("timeout")
			up.navigationMenuChanged = cmd.Flags().Changed("menu")
			if !cmd.Flags().Changed("remove-orphans") {
				create.removeOrphans = utils.StringToBool(os.Getenv(ComposeRemoveOrphans))
			}
			return validateFlags(&up, &create)
		}),
		RunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {
			create.ignoreOrphans = utils.StringToBool(project.Environment[ComposeIgnoreOrphans])
			if create.ignoreOrphans && create.removeOrphans {
				return fmt.Errorf("cannot combine %s and --remove-orphans", ComposeIgnoreOrphans)
			}
			if len(up.attach) != 0 && up.attachDependencies {
				return errors.New("cannot combine --attach and --attach-dependencies")
			}

			up.resolveNavigationMenu(dockerCli)

			if !p.All && len(project.Services) == 0 {
				return fmt.Errorf("no service selected")
			}

			return runUp(ctx, dockerCli, backendOptions, create, up, build, project, services)
		}),
		ValidArgsFunction: completeServiceNames(dockerCli, p),
	}
	flags := upCmd.Flags()
	flags.BoolVarP(&up.Detach, "detach", "d", false, "Detached mode: Run containers in the background")
	flags.BoolVar(&create.Build, "build", false, "Build images before starting containers")
	flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's policy")
	flags.StringVar(&create.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`)
	flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file")

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Pick one mode: either list the services explicitly with --attach (you may list dependencies too), or use --attach-dependencies alone.
  2. If you need a service plus its deps, name them all: `--attach web --attach db`.
  3. For full output, drop both flags (up attaches to all foreground services by default).

Example fix

# before
docker compose up --attach web --attach-dependencies

# after
docker compose up --attach web --attach db
Defensive patterns

Strategy: validation

Validate before calling

if [ -n "$ATTACH" ] && [ "$ATTACH_DEPS" = "true" ]; then
  echo "cannot combine --attach and --attach-dependencies" >&2
  exit 1
fi
docker compose up ${ATTACH:+--attach $ATTACH} ${ATTACH_DEPS:+--attach-dependencies}

Prevention

When it happens

Trigger: `docker compose up --attach web --attach-dependencies`, or any invocation where the --attach flag received at least one value together with boolean --attach-dependencies=true.

Common situations: Trying to see both a chosen service and its dependencies' logs by combining flags; CI scripts that layer flag variables (one adds --attach, another adds --attach-dependencies) into a single up command.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/d8ce376c3f7efe36. Report an issue: GitHub.