{"record":{"id":"d8ce376c3f7efe36","repo":"docker/compose","slug":"cannot-combine-attach-and-attach-dependencies","errorCode":null,"errorMessage":"cannot combine --attach and --attach-dependencies","messagePattern":"cannot combine --attach and --attach-dependencies","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/up.go","lineNumber":135,"sourceCode":"\tupCmd := &cobra.Command{\n\t\tUse:   \"up [OPTIONS] [SERVICE...]\",\n\t\tShort: \"Create and start containers\",\n\t\tPreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {\n\t\t\tcreate.pullChanged = cmd.Flags().Changed(\"pull\")\n\t\t\tcreate.timeChanged = cmd.Flags().Changed(\"timeout\")\n\t\t\tup.navigationMenuChanged = cmd.Flags().Changed(\"menu\")\n\t\t\tif !cmd.Flags().Changed(\"remove-orphans\") {\n\t\t\t\tcreate.removeOrphans = utils.StringToBool(os.Getenv(ComposeRemoveOrphans))\n\t\t\t}\n\t\t\treturn validateFlags(&up, &create)\n\t\t}),\n\t\tRunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {\n\t\t\tcreate.ignoreOrphans = utils.StringToBool(project.Environment[ComposeIgnoreOrphans])\n\t\t\tif create.ignoreOrphans && create.removeOrphans {\n\t\t\t\treturn fmt.Errorf(\"cannot combine %s and --remove-orphans\", ComposeIgnoreOrphans)\n\t\t\t}\n\t\t\tif len(up.attach) != 0 && up.attachDependencies {\n\t\t\t\treturn errors.New(\"cannot combine --attach and --attach-dependencies\")\n\t\t\t}\n\n\t\t\tup.resolveNavigationMenu(dockerCli)\n\n\t\t\tif !p.All && len(project.Services) == 0 {\n\t\t\t\treturn fmt.Errorf(\"no service selected\")\n\t\t\t}\n\n\t\t\treturn runUp(ctx, dockerCli, backendOptions, create, up, build, project, services)\n\t\t}),\n\t\tValidArgsFunction: completeServiceNames(dockerCli, p),\n\t}\n\tflags := upCmd.Flags()\n\tflags.BoolVarP(&up.Detach, \"detach\", \"d\", false, \"Detached mode: Run containers in the background\")\n\tflags.BoolVar(&create.Build, \"build\", false, \"Build images before starting containers\")\n\tflags.BoolVar(&create.noBuild, \"no-build\", false, \"Don't build an image, even if it's policy\")\n\tflags.StringVar(&create.Pull, \"pull\", \"policy\", `Pull image before running (\"always\"|\"missing\"|\"never\")`)\n\tflags.BoolVar(&create.removeOrphans, \"remove-orphans\", false, \"Remove containers for services not defined in the Compose file\")","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/up.go#L117-L153","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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)."],"exampleFix":"# before\ndocker compose up --attach web --attach-dependencies\n\n# after\ndocker compose up --attach web --attach db","handlingStrategy":"validation","validationCode":"if [ -n \"$ATTACH\" ] && [ \"$ATTACH_DEPS\" = \"true\" ]; then\n  echo \"cannot combine --attach and --attach-dependencies\" >&2\n  exit 1\nfi\ndocker compose up ${ATTACH:+--attach $ATTACH} ${ATTACH_DEPS:+--attach-dependencies}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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)."],"tags":["cli","up","flags","validation","attach"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}