{"record":{"id":"eaf88cfd31529b6f","repo":"docker/cli","slug":"invalid-image-source-source-cannot-be-empty","errorCode":null,"errorMessage":"invalid image source, source cannot be empty","messagePattern":"invalid image source, source cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/compose/convert/volume.go","lineNumber":98,"sourceCode":"\t\treturn result, nil\n\t}\n\n\tresult.VolumeOptions.Labels = addStackLabel(namespace, stackVolume.Labels)\n\tif stackVolume.Driver != \"\" || stackVolume.DriverOpts != nil {\n\t\tresult.VolumeOptions.DriverConfig = &mount.Driver{\n\t\t\tName:    stackVolume.Driver,\n\t\t\tOptions: stackVolume.DriverOpts,\n\t\t}\n\t}\n\n\treturn result, nil\n}\n\nfunc handleImageToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, error) {\n\tresult := createMountFromVolume(volume)\n\n\tif volume.Source == \"\" {\n\t\treturn mount.Mount{}, errors.New(\"invalid image source, source cannot be empty\")\n\t}\n\tif volume.Volume != nil {\n\t\treturn mount.Mount{}, errors.New(\"volume options are incompatible with type image\")\n\t}\n\tif volume.Bind != nil {\n\t\treturn mount.Mount{}, errors.New(\"bind options are incompatible with type image\")\n\t}\n\tif volume.Tmpfs != nil {\n\t\treturn mount.Mount{}, errors.New(\"tmpfs options are incompatible with type image\")\n\t}\n\tif volume.Cluster != nil {\n\t\treturn mount.Mount{}, errors.New(\"cluster options are incompatible with type image\")\n\t}\n\tif volume.Image != nil {\n\t\tresult.ImageOptions = &mount.ImageOptions{\n\t\t\tSubpath: volume.Image.Subpath,\n\t\t}\n\t}","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/compose/convert/volume.go#L80-L116","documentation":"Returned by handleImageToMount (volume.go:97-98) when a Compose service volume is type: image but has an empty 'source'. An image mount must name the image to mount from (the source field), so an empty source is rejected before the engine call. This mirrors the same pattern used for bind/npipe/cluster mounts requiring a non-empty source.","triggerScenarios":"In docker-compose.yml: { type: image, target: /app } with no source, or { type: image, source: \"\", target: /app }. The check at line 97 sees volume.Source == \"\" and returns the error.","commonSituations":"Using the short syntax '- /app' (which defaults to volume type) but intending an image mount. Forgetting the image reference when converting from a Dockerfile ref. Templating that emits an empty source.","solutions":["Add a 'source' field naming the image, e.g. source: myimg:latest.","Switch to long-form and set type: image plus source explicitly.","Validate with 'docker compose config'."],"exampleFix":"# before\nvolumes:\n  - type: image\n    target: /app\n\n# after\nvolumes:\n  - type: image\n    source: myrepo/myimg:latest\n    target: /app","handlingStrategy":"validation","validationCode":"// Ensure an image-type mount has a non-empty source.\nfunc validateImageMount(v composetypes.ServiceVolumeConfig) error {\n    if v.Type == \"image\" && v.Source == \"\" {\n        return errors.New(\"image mount requires a non-empty source (the image reference)\")\n    }\n    return nil\n}","typeGuard":"// imageMountHasSource reports whether an image-type mount names its source image.\nfunc imageMountHasSource(v composetypes.ServiceVolumeConfig) bool {\n    if v.Type != \"image\" {\n        return true\n    }\n    return strings.TrimSpace(v.Source) != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always provide 'source' (an image ref) for type: image mounts.","Prefer long-form volume entries when using non-volume types to avoid short-syntax defaults.","Validate compose files with 'docker compose config'."],"tags":["docker-compose","volumes","image-mount","mount","validation","convert"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}