{"record":{"id":"509af9fbf4012251","repo":"docker/compose","slug":"q-attribute-is-mandatory-to-push-an-image-for-ser","errorCode":null,"errorMessage":"%q attribute is mandatory to push an image for service %q","messagePattern":"%q attribute is mandatory to push an image for service %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/push.go","lineNumber":55,"sourceCode":")\n\nfunc (s *composeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error {\n\tif options.Quiet {\n\t\treturn s.push(ctx, project, options)\n\t}\n\treturn Run(ctx, func(ctx context.Context) error {\n\t\treturn s.push(ctx, project, options)\n\t}, \"push\", s.events)\n}\n\nfunc (s *composeService) push(ctx context.Context, project *types.Project, options api.PushOptions) error {\n\teg, ctx := errgroup.WithContext(ctx)\n\teg.SetLimit(s.maxConcurrency)\n\n\tfor _, service := range project.Services {\n\t\tif service.Build == nil || service.Image == \"\" {\n\t\t\tif options.ImageMandatory && service.Image == \"\" && service.Provider == nil {\n\t\t\t\treturn fmt.Errorf(\"%q attribute is mandatory to push an image for service %q\", \"service.image\", service.Name)\n\t\t\t}\n\t\t\ts.events.On(api.Resource{\n\t\t\t\tID:     service.Name,\n\t\t\t\tStatus: api.Done,\n\t\t\t\tText:   \"Skipped\",\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\ttags := []string{service.Image}\n\t\tif service.Build != nil {\n\t\t\ttags = append(tags, service.Build.Tags...)\n\t\t}\n\n\t\tfor _, tag := range tags {\n\t\t\teg.Go(func() error {\n\t\t\t\ts.events.On(newEvent(tag, api.Working, \"Pushing\"))\n\t\t\t\terr := s.pushServiceImage(ctx, tag, options.Quiet)\n\t\t\t\tif err != nil {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/push.go#L37-L73","documentation":"Raised by push when the caller set ImageMandatory and a service has no build section and no image attribute (and no provider). Without an image name there is nothing to tag or push, so compose refuses instead of silently skipping; services with build or image are unaffected.","triggerScenarios":"Running push with the image-mandatory option (mirrors docker compose push --ignore-buildable-failure=false semantics) on a project where a service omits image: and is not built from a Dockerfile.","commonSituations":"Copy-pasted service blocks missing the image key; services intended only as run-once utilities without an image; CI enforcing that every pushable service is explicitly tagged.","solutions":["Add an explicit image: <registry>/<repo>:<tag> to the service named in the error.","If the service should not be pushed, exclude it from the push selection (push specific services only).","If skipping is acceptable, clear the ImageMandatory option so the service is skipped with a 'Skipped' event instead of failing.","Add a build: section if the image is meant to be built and pushed under service.image."],"exampleFix":"# before\nservices:\n  migrate:\n    build: .            # no image: → push fails when mandatory\n\n# after\nservices:\n  migrate:\n    build: .\n    image: registry.example.com/team/migrate:1.2.0","handlingStrategy":"validation","validationCode":"func allServicesPushable(project *types.Project) error {\n\tfor name, svc := range project.Services {\n\t\tif svc.Image == \"\" && svc.Build == nil && svc.Provider == nil {\n\t\t\treturn fmt.Errorf(\"service %q lacks image and build; not pushable\", name)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := composeService.Push(ctx, project, api.PushOptions{ImageMandatory: true}); err != nil {\n    if strings.Contains(err.Error(), \"attribute is mandatory to push an image\") {\n        // add image: to the named service or drop ImageMandatory\n    }\n    return err\n}","preventionTips":["Give every pushable service an explicit image: tag.","Run docker compose config and grep for services without image/build before push in CI.","Scope push commands to the services you actually intend to publish."],"tags":["compose","push","service-image","validation"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}