{"record":{"id":"8eee29a796dec8f4","repo":"docker/compose","slug":"cannot-combine-s-and-remove-orphans","errorCode":null,"errorMessage":"cannot combine %s and --remove-orphans","messagePattern":"cannot combine (.+?) and --remove-orphans","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/up.go","lineNumber":132,"sourceCode":"\tup := upOptions{}\n\tcreate := createOptions{}\n\tbuild := buildOptions{ProjectOptions: p}\n\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\")","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/up.go#L114-L150","documentation":"Returned by the `up` command's RunE when both orphan removal and explicit orphan ignoring are active. create.removeOrphans is set by the --remove-orphans flag (or the COMPOSE_REMOVE_ORPHANS env var when the flag is not passed), while create.ignoreOrphans comes from the project-level COMPOSE_IGNORE_ORPHANS environment variable. The two options are contradictory — remove vs. keep containers for services no longer in the file — so Compose refuses to run.","triggerScenarios":"Project environment (or .env) sets COMPOSE_IGNORE_ORPHANS=true and the user also runs `docker compose up --remove-orphans`; or COMPOSE_REMOVE_ORPHANS=true in the environment and COMPOSE_IGNORE_ORPHANS=true in the project env. The check runs inside p.WithServices after project env resolution, so any combination resolving both to true trips it.","commonSituations":"CI pipelines that export COMPOSE_REMOVE_ORPHANS=true globally while a compose.yml (or exported project env) sets COMPOSE_IGNORE_ORPHANS to silence orphan warnings locally; teams sharing a .env with the variable set; renaming services and trying --remove-orphans to clean up while the ignore variable leaks from a wrapper script.","solutions":["Drop one of the two: either unset COMPOSE_IGNORE_ORPHANS for the project (`unset COMPOSE_IGNORE_ORPHANS` or remove it from .env/compose.yml environment) or omit --remove-orphans.","If you need removal, run with the variable explicitly disabled: `COMPOSE_IGNORE_ORPHANS=false docker compose up --remove-orphans` (the flag takes precedence when passed).","Audit .env files and exported variables in CI for COMPOSE_IGNORE_ORPHANS before adding --remove-orphans to scripts."],"exampleFix":"# before\n# .env contains COMPOSE_IGNORE_ORPHANS=true\ndocker compose up --remove-orphans\n\n# after\n# remove COMPOSE_IGNORE_ORPHANS from .env (or override it)\nCOMPOSE_IGNORE_ORPHANS=false docker compose up --remove-orphans","handlingStrategy":"validation","validationCode":"# in the wrapper, resolve the conflict before up\nif [ \"${COMPOSE_IGNORE_ORPHANS:-}\" = true ] && [[ \"$*\" == *--remove-orphans* ]]; then\n  unset COMPOSE_IGNORE_ORPHANS\nfi\ndocker compose up \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep orphan policy in exactly one place (env OR flag, never both).","Document which CI variables set COMPOSE_REMOVE_ORPHANS / COMPOSE_IGNORE_ORPHANS.","When adding --remove-orphans to a script, grep the .env for the ignore variable first."],"tags":["cli","up","flags","environment","orphans","compose"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}