docker/cli · error
invalid value for ' ': value is empty
Error message
invalid value for '%s': value is empty
What it means
Returned by MountOpt.Set (opts/mount.go:48) when an option is written as `key=` but the value (after TrimSpace) is empty. The parser requires every key=value option to carry a non-blank value; bare toggles must instead omit the '=' entirely (handled by the boolean-option branch).
Solutions
- Supply a concrete value: source=/var/data.
- If the option is a boolean toggle (readonly, ro, volume-nocopy, bind-create-src), drop the '=' entirely instead of writing readonly=.
- Ensure shell/env variables used to fill values are non-empty at evaluation time.
- Remove the field if it is not needed.
Example fix
// before --mount "type=volume,source=,target=/data" // after --mount "type=volume,source=mydata,target=/data"
Defensive patterns
Strategy: validation
Validate before calling
// requireNonEmpty checks key=value options carry a value before MountOpt.Set.
func requireNonEmpty(spec string) error {
r := csv.NewReader(strings.NewReader(spec))
fields, err := r.Read()
if err != nil {
return err
}
boolToggles := map[string]bool{"readonly": true, "ro": true, "volume-nocopy": true, "bind-nonrecursive": true, "bind-create-src": true}
for _, f := range fields {
k, v, has := strings.Cut(f, "=")
if has && strings.TrimSpace(v) == "" && !boolToggles[strings.ToLower(strings.TrimSpace(k))] {
return fmt.Errorf("option %q has empty value", k)
}
}
return nil
} Try / catch
if err := m.Set(spec); err != nil {
return fmt.Errorf("mount %q: %w", spec, err)
} Prevention
- Default unset template variables to a sentinel and fail loudly instead of emitting key=.
- For booleans, omit the '=' rather than writing toggle=.
- Validate generated mount strings against the known option set.
When it happens
Trigger: Passing `source=`, `target=`, `type=`, `volume-driver=` etc. in a --mount CSV — any field that has '=' followed by nothing or only whitespace.
Common situations: Templating/compose generation that emits `key=$VAR` with VAR unset, a trailing `=` typo, or copy-paste where the value was dropped.
Related errors
- invalid value for ' ' in ' ': value should not have…
- invalid field ' ' must be a key=value pair
- invalid option ' ' in ' ': option should not have whitespace
- invalid value for : (must be "enabled", "disabled"…
- invalid value for
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/a4642494368e6395.
Report an issue: GitHub.
Appendix: source
Thrown at opts/mount.go:48
csvReader := csv.NewReader(strings.NewReader(value))
fields, err := csvReader.Read()
if err != nil {
return err
}
mount := mounttypes.Mount{
Type: mounttypes.TypeVolume, // default to volume mounts
}
for _, field := range fields {
key, val, hasValue := strings.Cut(field, "=")
if k := strings.TrimSpace(key); k != key {
return fmt.Errorf("invalid option '%s' in '%s': option should not have whitespace", k, field)
}
if hasValue {
v := strings.TrimSpace(val)
if v == "" {
return fmt.Errorf("invalid value for '%s': value is empty", key)
}
if v != val {
return fmt.Errorf("invalid value for '%s' in '%s': value should not have whitespace", key, field)
}
}
// TODO(thaJeztah): these options should not be case-insensitive.
key = strings.ToLower(key)
if !hasValue {
switch key {
case "readonly", "ro", "volume-nocopy", "bind-nonrecursive", "bind-create-src":
// boolean values
default:
return fmt.Errorf("invalid field '%s' must be a key=value pair", field)
}
}
View on GitHub (pinned to 4f84911bfe)