docker/cli · error
invalid value for ' ' in ' ': value should not have…
Error message
invalid value for '%s' in '%s': value should not have whitespace
What it means
Returned by MountOpt.Set (opts/mount.go:51) when an option value has leading or trailing whitespace. The parser trims the value and compares against the raw value; if they differ it rejects the field, since embedded padding around values is almost always a mistake and would silently corrupt paths/names.
Solutions
- Trim spaces from values: source=/var/data (no padding).
- Avoid `key = value` style; use key=value with no surrounding whitespace.
- If whitespace inside the value is genuinely intended (e.g. a label), note this parser does not allow leading/trailing whitespace — sanitize first.
- Regenerate compose/templated mount strings without spaces around '='.
Example fix
// before --mount "type=volume,source= mydata ,target=/data" // after --mount "type=volume,source=mydata,target=/data"
Defensive patterns
Strategy: validation
Validate before calling
// rejectValueWhitespace ensures no value has surrounding whitespace.
func rejectValueWhitespace(spec string) error {
r := csv.NewReader(strings.NewReader(spec))
fields, err := r.Read()
if err != nil {
return err
}
for _, f := range fields {
_, v, has := strings.Cut(f, "=")
if has && v != strings.TrimSpace(v) {
return fmt.Errorf("value %q has surrounding whitespace", v)
}
}
return nil
} Try / catch
if err := m.Set(spec); err != nil {
return fmt.Errorf("mount %q: %w", spec, err)
} Prevention
- Generate mounts from structured fields; never string-format with padding.
- Trim generated values explicitly before joining.
- Add a unit test that asserts emitted specs round-trip through MountOpt.Set.
When it happens
Trigger: A --mount CSV field whose value has surrounding spaces or tabs, e.g. `source= foo`, `target=/data `, or a value embedded as ` source = /data `. Keys are checked separately (error 623); this is specifically the value side.
Common situations: Spaces around '=' for readability, tabs in generated YAML/CSV, or quoted shell values that retained padding.
Related errors
- invalid option ' ' in ' ': option should not have whitespace
- invalid value for ' ': value is empty
- invalid field ' ' must be a key=value pair
- 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/cb9a941580c3fe13.
Report an issue: GitHub.
Appendix: source
Thrown at opts/mount.go:51
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)
}
}
switch key {
case "type":
mount.Type = mounttypes.Type(strings.ToLower(val))View on GitHub (pinned to 4f84911bfe)