{"record":{"id":"17e6e537479d2bc0","repo":"docker/compose","slug":"service-q-build-platforms-does-not-support-value","errorCode":null,"errorMessage":"service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s","messagePattern":"service %q build\\.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/options.go","lineNumber":68,"sourceCode":"\t\tif service.Build == nil || service.Platform != \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tservice.Platform = defaultPlatform\n\t\tproject.Services[name] = service\n\t}\n}\n\nfunc applyPlatforms(project *types.Project, buildForSinglePlatform bool) error {\n\tdefaultPlatform := project.Environment[\"DOCKER_DEFAULT_PLATFORM\"]\n\tfor name, service := range project.Services {\n\t\tif service.Build == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\t// default platform only applies if the service doesn't specify\n\t\tif defaultPlatform != \"\" && service.Platform == \"\" {\n\t\t\tif len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, defaultPlatform) {\n\t\t\t\treturn fmt.Errorf(\"service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s\", name, defaultPlatform)\n\t\t\t}\n\t\t\tservice.Platform = defaultPlatform\n\t\t}\n\n\t\tif service.Platform != \"\" {\n\t\t\tif len(service.Build.Platforms) > 0 {\n\t\t\t\tif !slices.Contains(service.Build.Platforms, service.Platform) {\n\t\t\t\t\treturn fmt.Errorf(\"service %q build configuration does not support platform: %s\", name, service.Platform)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif buildForSinglePlatform || len(service.Build.Platforms) == 0 {\n\t\t\t\t// if we're building for a single platform, we want to build for the platform we'll use to run the image\n\t\t\t\t// similarly, if no build platforms were explicitly specified, it makes sense to build for the platform\n\t\t\t\t// the image is designed for rather than allowing the builder to infer the platform\n\t\t\t\tservice.Build.Platforms = []string{service.Platform}\n\t\t\t}\n\t\t}","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/options.go#L50-L86","documentation":"When DOCKER_DEFAULT_PLATFORM is set in the project environment and a service declares `platforms:` under its build section without also setting a top-level `platform:`, compose requires the env-var platform to be listed in build.platforms. If it is not, platform resolution fails because the image would be built/tagged for a platform the build config explicitly excludes.","triggerScenarios":"Setting DOCKER_DEFAULT_PLATFORM=linux/arm64 while a service's build section lists only `platforms: [linux/amd64]` and no service-level `platform:`. The env value is checked via slices.Contains against build.Platforms and misses.","commonSituations":"Apple Silicon or ARM CI runners that export DOCKER_DEFAULT_PLATFORM globally, combined with compose files pinned to amd64 builds; cross-build setups where the platform list was narrowed and the default env leaked in from a login shell or Docker Desktop setting.","solutions":["Add the DOCKER_DEFAULT_PLATFORM value to the service's `build.platforms` list.","Or set an explicit service-level `platform:` so the env default no longer applies.","Or unset DOCKER_DEFAULT_PLATFORM for the compose invocation if the service should build for its configured platforms only."],"exampleFix":"# before\nservices:\n  api:\n    build:\n      platforms: [linux/amd64]\n# with DOCKER_DEFAULT_PLATFORM=linux/arm64\n\n# after\nservices:\n  api:\n    platform: linux/amd64\n    build:\n      platforms: [linux/amd64]","handlingStrategy":"validation","validationCode":"# bash: check platform coverage before compose does\nDEFAULT_PLAT=\"${DOCKER_DEFAULT_PLATFORM:-}\"\nif [ -n \"$DEFAULT_PLAT\" ]; then\n  docker compose config --services | while read -r svc; do\n    plats=$(docker compose config --format json 2>/dev/null | jq -r --arg s \"$svc\" '.services[$s].build.platforms // [] | join(\",\")')\n    [ -z \"$plats\" ] && continue\n    case \",$plats,\" in *\",$DEFAULT_PLAT,\"*) ;; *) echo \"$svc build.platforms lacks $DEFAULT_PLAT\" >&2; exit 2;; esac\n  done\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set an explicit `platform:` on any service that also declares build.platforms.","Don't export DOCKER_DEFAULT_PLATFORM globally; scope it per command."],"tags":["platform","build","environment","arm64","validation"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}