{"record":{"id":"328881de5f7a112c","repo":"docker/compose","slug":"service-q-build-configuration-does-not-support-pl-328881","errorCode":null,"errorMessage":"service %q build configuration does not support platform: %s","messagePattern":"service %q build configuration does not support platform: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/api/api.go","lineNumber":250,"sourceCode":"func (o BuildOptions) Apply(project *types.Project) error {\n\tplatform := project.Environment[\"DOCKER_DEFAULT_PLATFORM\"]\n\tfor name, service := range project.Services {\n\t\tif service.Provider == nil && service.Image == \"\" && service.Build == nil {\n\t\t\treturn fmt.Errorf(\"invalid service %q. Must specify either image or build\", name)\n\t\t}\n\n\t\tif service.Build == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif platform != \"\" {\n\t\t\tif len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, platform) {\n\t\t\t\treturn fmt.Errorf(\"service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s\", name, platform)\n\t\t\t}\n\t\t\tservice.Platform = platform\n\t\t}\n\t\tif service.Platform != \"\" {\n\t\t\tif len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, service.Platform) {\n\t\t\t\treturn fmt.Errorf(\"service %q build configuration does not support platform: %s\", name, service.Platform)\n\t\t\t}\n\t\t}\n\n\t\tservice.Build.Pull = service.Build.Pull || o.Pull\n\t\tservice.Build.NoCache = service.Build.NoCache || o.NoCache\n\n\t\tproject.Services[name] = service\n\t}\n\treturn nil\n}\n\n// CreateOptions group options of the Create API\ntype CreateOptions struct {\n\tBuild *BuildOptions\n\t// Services defines the services user interacts with\n\tServices []string\n\t// Remove legacy containers for services that are not defined in the project\n\tRemoveOrphans bool","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/api/api.go#L232-L268","documentation":"BuildOptions.Apply enforces that a service's resolved service.Platform (set via the platform: field on the service, the DOCKER_DEFAULT_PLATFORM env var applied earlier, or API options) is contained in the build.platforms list when that list is non-empty. This keeps the built image consistent with the platform the service will run on; a mismatch would produce an image for the wrong OS/architecture.","triggerScenarios":"A service sets platform: linux/amd64 while build.platforms only contains linux/arm64; DOCKER_DEFAULT_PLATFORM is set to a value included in platforms for some services but a service also carries its own conflicting platform: key; API callers pass a platform in options that collides with the pinned build.platforms.","commonSituations":"Cross-arch projects where build.platforms is intentionally narrow but a service-level platform: was copied from another service; mixing the deprecated service platform syntax with the modern build.platforms syntax; renames or refactors that left a stale platform: behind.","solutions":["Make service.platform match one of the entries in build.platforms (same os/arch string, e.g. linux/amd64)","Remove the service-level platform: key and let build.platforms drive the target","Add the desired platform to build.platforms","Run docker compose config to see the effective platform and platforms values side by side"],"exampleFix":"# before (compose.yaml)\nservices:\n  web:\n    platform: linux/amd64\n    build:\n      platforms: [linux/arm64]\n# after\nservices:\n  web:\n    platform: linux/arm64\n    build:\n      platforms: [linux/arm64]\n","handlingStrategy":"validation","validationCode":"// Reject platform/platforms mismatches before calling Apply:\nfor name, svc := range project.Services {\n\tif svc.Build == nil || svc.Platform == \"\" {\n\t\tcontinue\n\t}\n\tif len(svc.Build.Platforms) > 0 && !slices.Contains(svc.Build.Platforms, svc.Platform) {\n\t\treturn fmt.Errorf(\"service %s: platform %s not in build.platforms\", name, svc.Platform)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one source of truth: either service.platform or build.platforms, not both","Script a lint that parses compose.yaml and cross-checks platform values","Run docker compose config before build in CI to surface the resolved platform"],"tags":["platform","validation","build","service-config"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}