{"record":{"id":"c1e45b409683cc5e","repo":"docker/compose","slug":"build-and-no-build-are-incompatible","errorCode":null,"errorMessage":"--build and --no-build are incompatible","messagePattern":"--build and --no-build are incompatible","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/create.go","lineNumber":66,"sourceCode":"\ttimeChanged   bool\n\ttimeout       int\n\tquietPull     bool\n\tscale         []string\n\tAssumeYes     bool\n}\n\nfunc createCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {\n\topts := createOptions{}\n\tbuildOpts := buildOptions{\n\t\tProjectOptions: p,\n\t}\n\tcmd := &cobra.Command{\n\t\tUse:   \"create [OPTIONS] [SERVICE...]\",\n\t\tShort: \"Creates containers for a service\",\n\t\tPreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {\n\t\t\topts.pullChanged = cmd.Flags().Changed(\"pull\")\n\t\t\tif opts.Build && opts.noBuild {\n\t\t\t\treturn fmt.Errorf(\"--build and --no-build are incompatible\")\n\t\t\t}\n\t\t\tif opts.forceRecreate && opts.noRecreate {\n\t\t\t\treturn fmt.Errorf(\"--force-recreate and --no-recreate are incompatible\")\n\t\t\t}\n\t\t\treturn nil\n\t\t}),\n\t\tRunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {\n\t\t\treturn runCreate(ctx, dockerCli, backendOptions, opts, buildOpts, project, services)\n\t\t}),\n\t\tValidArgsFunction: completeServiceNames(dockerCli, p),\n\t}\n\tflags := cmd.Flags()\n\tflags.BoolVar(&opts.Build, \"build\", false, \"Build images before starting containers\")\n\tflags.BoolVar(&opts.noBuild, \"no-build\", false, \"Don't build an image, even if it's policy\")\n\tflags.StringVar(&opts.Pull, \"pull\", \"policy\", `Pull image before running (\"always\"|\"missing\"|\"never\"|\"build\")`)\n\tflags.BoolVar(&opts.quietPull, \"quiet-pull\", false, \"Pull without printing progress information\")\n\tflags.BoolVar(&opts.forceRecreate, \"force-recreate\", false, \"Recreate containers even if their configuration and image haven't changed\")\n\tflags.BoolVar(&opts.noRecreate, \"no-recreate\", false, \"If containers already exist, don't recreate them. Incompatible with --force-recreate.\")","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/create.go#L48-L84","documentation":"`docker compose create` rejects the simultaneous use of `--build` (force-build images before creating containers) and `--no-build` (never build). The PreRunE guard fails fast because the two flags encode contradictory build policies.","triggerScenarios":"Running `docker compose create --build --no-build` (directly or via a wrapper/alias that always adds one of the flags while the user types the other).","commonSituations":"Shell aliases or CI templates that hardcode `--no-build` for speed, then a developer adds `--build` to refresh an image; scripts forwarding both flags from independent toggles without mutual exclusion logic.","solutions":["Remove one of the two flags — decide whether images should be built or not for this invocation.","If flags come from script variables, gate them: only pass `--build` when build is enabled, only pass `--no-build` when it is disabled.","Check `alias docker-compose` / function wrappers for hardcoded flags."],"exampleFix":"# before\ndocker compose create --build --no-build\n\n# after\n# pick one policy:\ndocker compose create --build   # or: docker compose create --no-build","handlingStrategy":"validation","validationCode":"# bash: mutually exclusive build policy\nBUILD_ARGS=()\nif [ \"$WANT_BUILD\" = true ]; then BUILD_ARGS+=(--build); elif [ \"$WANT_BUILD\" = false ]; then BUILD_ARGS+=(--no-build); fi\ndocker compose create \"${BUILD_ARGS[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model build policy as a single three-state option (default/build/no-build), not two booleans.","Grep CI scripts for '--build.*--no-build' as a cheap pre-flight check."],"tags":["cli","create","build","flags","conflict"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}