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
- Pick one mode: either list the services explicitly with --attach (you may list dependencies too), or use --attach-dependencies alone.
- If you need a service plus its deps, name them all: `--attach web --attach db`.
- 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
- Pick one attachment mode per invocation; name dependencies explicitly when you need them attached.
- Keep flag-layering in scripts mutually exclusive by design (set -o errtrace style guards).
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
- --wait cannot be combined with --abort-on-container-exit, --
- --detach cannot be combined with --abort-on-container-exit,
- --wait-timeout must be a non-negative integer
- --abort-on-container-failure cannot be combined with --abort
- --build and --no-build are incompatible
AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15).
Data as JSON: /api/errors/d8ce376c3f7efe36.
Report an issue: GitHub.