{"record":{"id":"190dc3c56bd91774","repo":"docker/compose","slug":"invalid-value-for-rmi-q","errorCode":null,"errorMessage":"invalid value for --rmi: %q","messagePattern":"invalid value for --rmi: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/down.go","lineNumber":55,"sourceCode":"\tremoveOrphans bool\n\ttimeChanged   bool\n\ttimeout       int\n\tvolumes       bool\n\timages        string\n}\n\nfunc downCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {\n\topts := downOptions{\n\t\tProjectOptions: p,\n\t}\n\tdownCmd := &cobra.Command{\n\t\tUse:   \"down [OPTIONS] [SERVICES]\",\n\t\tShort: \"Stop and remove containers, networks\",\n\t\tPreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {\n\t\t\topts.timeChanged = cmd.Flags().Changed(\"timeout\")\n\t\t\tif opts.images != \"\" {\n\t\t\t\tif opts.images != \"all\" && opts.images != \"local\" {\n\t\t\t\t\treturn fmt.Errorf(\"invalid value for --rmi: %q\", opts.images)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t}),\n\t\tRunE: Adapt(func(ctx context.Context, args []string) error {\n\t\t\treturn runDown(ctx, dockerCli, backendOptions, opts, args)\n\t\t}),\n\t\tValidArgsFunction: completeServiceNames(dockerCli, p),\n\t}\n\tflags := downCmd.Flags()\n\tremoveOrphans := utils.StringToBool(os.Getenv(ComposeRemoveOrphans))\n\tflags.BoolVar(&opts.removeOrphans, \"remove-orphans\", removeOrphans, \"Remove containers for services not defined in the Compose file\")\n\tflags.IntVarP(&opts.timeout, \"timeout\", \"t\", 0, \"Specify a shutdown timeout in seconds\")\n\tflags.BoolVarP(&opts.volumes, \"volumes\", \"v\", false, `Remove named volumes declared in the \"volumes\" section of the Compose file and anonymous volumes attached to containers`)\n\tflags.StringVar(&opts.images, \"rmi\", \"\", `Remove images used by services. \"local\" remove only images that don't have a custom tag (\"local\"|\"all\")`)\n\tflags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {\n\t\tif name == \"volume\" {\n\t\t\tname = \"volumes\"","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/down.go#L37-L73","documentation":"The `--rmi` flag on `docker compose down` accepts only `all` or `local`. The PreRunE guard rejects any other non-empty value with this error, echoing the offending string.","triggerScenarios":"Running `docker compose down --rmi always` (thinking it mirrors pull policy wording), `--rmi none`, or `--rmi ${FLAG}` with an empty/typo variable value.","commonSituations":"Confusion with `docker image rm` semantics or with `--pull always` phrasing; CI teardown scripts forwarding an unvalidated variable to --rmi.","solutions":["Use `--rmi all` (remove all images used by the project) or `--rmi local` (only images without a custom tag).","Omit `--rmi` entirely if no image removal is wanted — there is no 'none' value.","Guard script variables: only append `--rmi` when its value is exactly `all` or `local`."],"exampleFix":"# before\ndocker compose down --rmi always\n\n# after\ndocker compose down --rmi all","handlingStrategy":"validation","validationCode":"# bash\nRMI_ARGS=()\ncase \"${RMI:-}\" in \"\") ;; all|local) RMI_ARGS=(--rmi \"$RMI\");; *) echo \"--rmi must be all|local\" >&2; exit 2;; esac\ndocker compose down \"${RMI_ARGS[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map a single tri-state option (none/all/local) to the flag in wrappers.","Don't reuse pull-policy vocabulary for --rmi."],"tags":["cli","down","rmi","flags","validation"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}