{"record":{"id":"156c6136cbf05081","repo":"docker/cli","slug":"invalid-bind-source-source-cannot-be-empty","errorCode":null,"errorMessage":"invalid bind source, source cannot be empty","messagePattern":"invalid bind source, source cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/compose/convert/volume.go","lineNumber":124,"sourceCode":"\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}\n\treturn result, nil\n}\n\nfunc handleBindToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, error) {\n\tresult := createMountFromVolume(volume)\n\n\tif volume.Source == \"\" {\n\t\treturn mount.Mount{}, errors.New(\"invalid bind 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 bind\")\n\t}\n\tif volume.Image != nil {\n\t\treturn mount.Mount{}, errors.New(\"image options are incompatible with type bind\")\n\t}\n\tif volume.Tmpfs != nil {\n\t\treturn mount.Mount{}, errors.New(\"tmpfs options are incompatible with type bind\")\n\t}\n\tif volume.Cluster != nil {\n\t\treturn mount.Mount{}, errors.New(\"cluster options are incompatible with type bind\")\n\t}\n\tif volume.Bind != nil {\n\t\tresult.BindOptions = &mount.BindOptions{\n\t\t\tPropagation: mount.Propagation(volume.Bind.Propagation),\n\t\t}\n\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/compose/convert/volume.go#L106-L142","documentation":"Returned by handleBindToMount (cli/compose/convert/volume.go:123-124). A bind mount maps an existing host path into the container, so a non-empty source path is mandatory. When type is \"bind\" but Source is the empty string, the converter cannot construct a valid mount and aborts before reaching the engine.","triggerScenarios":"A ServiceVolumeConfig with Type==\"bind\" and Source==\"\" passed to convert.Volumes() / convertVolumeToMount(). Typically a compose entry `type: bind` with no `source:` key, or a `source:` whose interpolation resolved to empty.","commonSituations":"`source: ${HOST_PATH}` where HOST_PATH is unset/unexported; YAML key typo like `src:` instead of `source:`; stripping the source line during a refactor; inheriting a template that expected a host path variable.","solutions":["Add an explicit non-empty `source:` host path to the bind volume entry.","Make interpolation failures loud: `source: ${HOST_PATH:?HOST_PATH must be set}`.","If you wanted an anonymous in-container volume, change `type:` to `volume`; if you wanted an in-memory filesystem, change it to `tmpfs`."],"exampleFix":"# before\nvolumes:\n  - type: bind\n    target: /cfg\n    source: ${HOST_CFG}\n\n# after (require the var)\nvolumes:\n  - type: bind\n    target: /cfg\n    source: ${HOST_CFG:?HOST_CFG must be set}","handlingStrategy":"validation","validationCode":"for i, v := range serviceVolumes {\n    if v.Type == \"bind\" && strings.TrimSpace(v.Source) == \"\" {\n        return fmt.Errorf(\"service volume[%d] target=%q: bind mount requires a non-empty source\", i, v.Target)\n    }\n}","typeGuard":null,"tryCatchPattern":"mounts, err := convert.Volumes(serviceVolumes, stackVolumes, namespace)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid bind source\") {\n        return fmt.Errorf(\"compose config error: %w (set source: to a host path; use ${VAR:?msg} for interpolation)\", err)\n    }\n    return err\n}","preventionTips":["Always set an explicit `source:` for bind mounts.","Use `${VAR:?error message}` interpolation so unset variables fail loudly instead of producing empty sources.","Validate the rendered compose file (`docker compose config`) in CI before deploying."],"tags":["docker","compose","volumes","bind-mount","config-validation","env-interpolation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}