{"record":{"id":"b701b65d4116853c","repo":"slimtoolkit/slim","slug":"bad-image-reference","errorCode":null,"errorMessage":"bad image reference","messagePattern":"bad image reference","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/compose/execution.go","lineNumber":1007,"sourceCode":"\t\t\tline = strings.TrimSpace(line)\n\t\t\tif len(line) == 0 {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif strings.HasPrefix(line, \"#\") {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tresult = append(result, line)\n\t\t}\n\t}\n\n\treturn result\n}\n\nfunc HasImage(dclient *dockerapi.Client, imageRef string) (bool, error) {\n\tif imageRef == \"\" || imageRef == \".\" || imageRef == \"..\" {\n\t\treturn false, fmt.Errorf(\"bad image reference\")\n\t}\n\n\tinfo, err := dockerutil.HasImage(dclient, imageRef)\n\tif err != nil {\n\t\tif err == dockerapi.ErrNoSuchImage ||\n\t\t\terr == dockerutil.ErrNotFound {\n\t\t\treturn false, nil\n\t\t}\n\n\t\treturn false, err\n\t}\n\n\tlog.Debugf(\"compose.HasImage(%s): image identity - %#v\", imageRef, info)\n\n\tvar repo string\n\tvar tag string\n\tif strings.Contains(imageRef, \"@\") {\n\t\tparts := strings.SplitN(imageRef, \"@\", 2)","sourceCodeStart":989,"sourceCodeEnd":1025,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/compose/execution.go#L989-L1025","documentation":"HasImage validates the image reference before checking the Docker daemon: an empty string, '.', or '..' is not a valid image reference, so it returns 'bad image reference' without contacting the daemon. It guards dockerutil.HasImage from receiving a meaningless reference.","triggerScenarios":"Calling HasImage (e.g. from PrepareService) with service.Image set to \"\", \".\", or \"..\" — typically when a compose file has an empty or dot-valued image field.","commonSituations":"A docker-compose.yml with `image: .` or an image key left empty; templating/interpolation that resolved the image variable to empty; passing a relative-path-like value instead of an image reference.","solutions":["Set a valid image reference (name[:tag]) in the service's `image:` field","Check compose variable interpolation — an env var feeding ${IMAGE} may be unset, producing an empty value","If the service should be built instead, add a `build:` section and enable image building rather than leaving image empty"],"exampleFix":"// before (docker-compose.yml)\nservices:\n  api:\n    image: ${API_IMAGE}     # API_IMAGE unset -> \"\" -> bad image reference\n// after\nservices:\n  api:\n    image: myapp/api:1.0.0","handlingStrategy":"validation","validationCode":"func validImageRef(ref string) bool {\n    return ref != \"\" && ref != \".\" && ref != \"..\" &&\n        strings.ContainsAny(ref, \":/@\") || // crude: has tag/registry separator\n        regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._/-]*(:[\\w.-]+)?$`).MatchString(ref)\n}","typeGuard":null,"tryCatchPattern":"ok, err := compose.HasImage(cli, img)\nif err != nil {\n    if strings.Contains(err.Error(), \"bad image reference\") {\n        return fmt.Errorf(\"image ref %q is empty/invalid, fix compose image field: %w\", img, err)\n    }\n    return err\n}","preventionTips":["Never leave the `image:` key empty or set it to \".\"/\"..\"","Check env vars used in image interpolation are set (docker compose config)","Use full name:tag references instead of relative-looking paths"],"tags":["compose","docker","image-reference"],"backgroundTag":"invalid-image-reference","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}