slimtoolkit/slim · error
invalid publish-port: %s
Error message
invalid publish-port: %s
What it means
ParsePortBindings returns 'invalid publish-port: %s' when a publish-port value does not match any accepted hostIP:hostPort:containerPort shape. The parser switches on the number of ':'-separated parts and the default branch rejects values with an unexpected structure. Valid forms are like '80', '8080:80', '127.0.0.1:8080:80' (with optional protocol suffix).
Source
Thrown at pkg/app/master/command/clifvparser.go:123
portKey = parts[1]
} else {
portKey = fmt.Sprintf("%s/tcp", parts[1])
}
case 3:
hostIP = parts[0]
if len(parts[1]) > 0 {
hostPort = parts[1]
} else {
hostPort = parts[2]
}
if strings.Contains(parts[2], "/") {
portKey = parts[2]
} else {
portKey = fmt.Sprintf("%s/tcp", parts[2])
}
default:
return nil, fmt.Errorf("invalid publish-port: %s", raw)
}
portBindings[docker.Port(portKey)] = []docker.PortBinding{{
HostIP: hostIP,
HostPort: hostPort,
}}
}
return portBindings, nil
}
func IsOneSpace(value string) bool {
if len(value) > 0 && utf8.RuneCountInString(value) == 1 {
r, _ := utf8.DecodeRuneInString(value)
if r != utf8.RuneError && unicode.IsSpace(r) {
return true
}
}View on GitHub (pinned to 81940d17fa)
Solutions
- Use one of the supported forms: 'containerPort', 'host:container', or 'ip:host:container'.
- Wrap IPv6 host addresses in brackets, e.g. '[::1]:8080:80', so colon splitting stays correct.
- Remove duplicate or extra segments (max three colon-separated parts).
- Echo the offending raw value against docker run -p documentation to spot the deviation.
Example fix
// before
publish := []string{"8080:80:80:extra"}
// after
publish := []string{"8080:80"} Defensive patterns
Strategy: validation
Validate before calling
parts := strings.Split(raw, ":")
switch len(parts) {
case 1, 2, 3:
for _, p := range parts {
if strings.TrimSpace(p) == "" {
return fmt.Errorf("empty segment in publish-port %q", raw)
}
}
default:
return fmt.Errorf("publish-port %q: expected at most 3 colon-separated parts", raw)
} Try / catch
bindings, err := command.ParsePortBindings(values)
if err != nil {
if strings.Contains(err.Error(), "invalid publish-port") {
return fmt.Errorf("supported forms: port | host:port | ip:host:port: %w", err)
}
return err
} Prevention
- Stick to docker run -p accepted shapes: port, host:port, ip:host:port.
- Bracket IPv6 host addresses so ':' splitting works.
- Avoid extra protocol segments unsupported by this parser.
- Test publish parsing with representative flag values in CI.
When it happens
Trigger: Calling ParsePortBindings (from CommandFlagValues or inline parsers) with values like 'tcp://80', '80:80:80:80', empty segments, or other malformed publish specs.
Common situations: Typos with extra colons; IPv6 addresses with unbracketed colons confusing the splitter; users pasting full docker run -p syntax variants the slim parser does not support.
Related errors
- invalid EXPOSE format: %s
- invalid port range in EXPOSE: %s / error: %s
- slim: error => missing comms ports
- invalid context directory
- no service image
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/dbc3cf6c8842ad0e.
Report an issue: GitHub.