docker/cli · error
invalid type %T for service build
Error message
invalid type %T for service build
What it means
Thrown by transformBuildConfig, the transformer for a service's `build` field. It accepts a string (context path) or a map (full build config with context/args/dockerfile). Any other type (list, int, bool) is rejected.
Solutions
- Use a string context: `build: .`
- Or a map: `build: { context: ., dockerfile: Dockerfile }`.
Example fix
# before
web:
build:
- .
- Dockerfile
# after
web:
build:
context: .
dockerfile: Dockerfile Defensive patterns
Strategy: type-guard
Validate before calling
func validateBuild(build any) error {
switch build.(type) {
case string, map[string]any:
return nil
default:
return fmt.Errorf("build must be string or map, got %T", build)
}
} Type guard
func isValidBuild(v any) bool {
switch v.(type) {
case string, map[string]any:
return true
}
return false
} Prevention
- Use `build: <context>` or a `build: { context: ..., dockerfile: ... }` map.
- Don't turn the build block into a list.
- Render with `docker compose config`.
When it happens
Trigger: A service defines `build:` as a list (`build: [., Dockerfile]`) or a scalar number/bool.
Common situations: Mis-indenting the build block into a list; templating that yields a non-string/map.
Related errors
- invalid type %T for ulimits
- invalid type %T for map[string]string
- invalid type %T for port
- invalid type %T for secret
- invalid type %T for service volume
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/96cef51053663af9.
Report an issue: GitHub.
Appendix: source
Thrown at cli/compose/loader/loader.go:758
var transformStringSourceMap TransformerFunc = func(data any) (any, error) {
switch value := data.(type) {
case string:
return map[string]any{"source": value}, nil
case map[string]any:
return data, nil
default:
return data, fmt.Errorf("invalid type %T for secret", value)
}
}
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 {View on GitHub (pinned to 4f84911bfe)