docker/cli · error

invalid type %T for service volume

Error message

invalid type %T for service volume

What it means

Thrown by transformServiceVolumeConfig, the transformer for one entry of a service's `volumes` list. Each entry must be a string (short syntax `src:tgt:mode`) or a map (long form). Any other type is rejected.

Solutions

  1. Use the short string form: `volumes: ["./data:/data"]`.
  2. Or the long map form: `volumes: [ { type: bind, source: ./data, target: /data } ]`.

Example fix

# before
web:
  volumes:
    - ./data
      /data
# after
web:
  volumes:
    - "./data:/data"
Defensive patterns

Strategy: type-guard

Validate before calling

func validateVolumeEntries(volumes any) error {
    list, ok := volumes.([]any)
    if !ok {
        return nil
    }
    for i, e := range list {
        switch e.(type) {
        case string, map[string]any:
        default:
            return fmt.Errorf("volumes[%d]: invalid type %T", i, e)
        }
    }
    return nil
}

Type guard

func isVolumeEntry(v any) bool {
    switch v.(type) {
    case string, map[string]any:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: A `volumes:` list contains an int, bool, nested list, or null instead of a string/map entry.

Common situations: Bad indentation turning a long-form map into a scalar; templating that emits empty entries.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/0902a8bbf803d1ec. Report an issue: GitHub.

Appendix: source

Thrown at cli/compose/loader/loader.go:769

var transformBuildConfig TransformerFunc = func(data any) (any, error) {
	switch value := data.(type) {
	case string:
		return map[string]any{"context": value}, nil
	case map[string]any:
		return data, nil
	default:
		return data, fmt.Errorf("invalid type %T for service build", value)
	}
}

var transformServiceVolumeConfig TransformerFunc = func(data any) (any, error) {
	switch value := data.(type) {
	case string:
		return volumespec.Parse(value)
	case map[string]any:
		return data, nil
	default:
		return data, fmt.Errorf("invalid type %T for service volume", value)
	}
}

var transformServiceNetworkMap TransformerFunc = func(value any) (any, error) {
	if list, ok := value.([]any); ok {
		mapValue := map[any]any{}
		for _, name := range list {
			mapValue[name] = nil
		}
		return mapValue, nil
	}
	return value, nil
}

var transformStringOrNumberList TransformerFunc = func(value any) (any, error) {
	list := value.([]any)
	result := make([]string, len(list))
	for i, item := range list {

View on GitHub (pinned to 4f84911bfe)