{"record":{"id":"c798957b2d897054","repo":"docker/compose","slug":"build-and-no-build-are-incompatible-c79895","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/up.go","lineNumber":207,"sourceCode":"//nolint:gocyclo\nfunc validateFlags(up *upOptions, create *createOptions) error {\n\tif up.waitTimeout < 0 {\n\t\treturn fmt.Errorf(\"--wait-timeout must be a non-negative integer\")\n\t}\n\tif up.exitCodeFrom != \"\" && !up.cascadeFail {\n\t\tup.cascadeStop = true\n\t}\n\tif up.cascadeStop && up.cascadeFail {\n\t\treturn fmt.Errorf(\"--abort-on-container-failure cannot be combined with --abort-on-container-exit\")\n\t}\n\tif up.wait {\n\t\tif up.attachDependencies || up.cascadeStop || len(up.attach) > 0 {\n\t\t\treturn fmt.Errorf(\"--wait cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies\")\n\t\t}\n\t\tup.Detach = true\n\t}\n\tif create.Build && create.noBuild {\n\t\treturn fmt.Errorf(\"--build and --no-build are incompatible\")\n\t}\n\tif up.Detach && (up.attachDependencies || up.cascadeStop || up.cascadeFail || len(up.attach) > 0 || up.watch) {\n\t\tif up.wait {\n\t\t\treturn fmt.Errorf(\"--wait cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch\")\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch\")\n\t\t}\n\t}\n\tif create.noInherit && create.noRecreate {\n\t\treturn fmt.Errorf(\"--no-recreate and --renew-anon-volumes are incompatible\")\n\t}\n\tif create.forceRecreate && create.noRecreate {\n\t\treturn fmt.Errorf(\"--force-recreate and --no-recreate are incompatible\")\n\t}\n\tif create.recreateDeps && create.noRecreate {\n\t\treturn fmt.Errorf(\"--always-recreate-deps and --no-recreate are incompatible\")\n\t}\n\tif create.noBuild && up.watch {","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/up.go#L189-L225","documentation":"Returned by validateFlags for `docker compose up` when both --build and --no-build are passed. --build forces building images before starting; --no-build forbids building even if policy suggests it. They are direct negations, so validateFlags rejects the combination before any work starts.","triggerScenarios":"`docker compose up --build --no-build`; wrapper scripts that append both flags from independent toggles (e.g. ALWAYS_BUILD and SKIP_BUILD env-derived flags concatenated into one command).","commonSituations":"Makefile/CI matrix where a 'fast path' adds --no-build and a 'rebuild path' adds --build and both end up enabled; aliases or shell history editing leaving a stale flag in place.","solutions":["Remove one flag — decide whether this run builds (`--build`) or reuses existing images (`--no-build`, or just omit both to follow pull policy).","Fix flag-assembly logic in scripts so the two toggles are mutually exclusive (if/else, not independent appends)."],"exampleFix":"# before\ndocker compose up --build --no-build\n\n# after\ndocker compose up --build   # or: docker compose up --no-build","handlingStrategy":"validation","validationCode":"if [[ \"$UP_FLAGS\" == *--build* && \"$UP_FLAGS\" == *--no-build* ]]; then\n  echo 'choose --build or --no-build, not both' >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model build policy as one variable: BUILD_FLAG in {--build, --no-build, ''}.","Review accumulated Makefile targets before adding negating flags."],"tags":["cli","up","flags","validation","build","compose"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}