GoogleContainerTools/jib · error · BadContainerConfigurationFormatException
Invalid port configuration: '" + port + "'.
Error message
Invalid port configuration: '" + port + "'.
What it means
Thrown by JsonToImageTranslator.portMapToSet when an entry key in the container configuration's 'ports' map fails to match the expected '<portNum>[/protocol]' pattern (PORT_PATTERN). Jib maps the Dockerfile/config JSON EXPOSE-style port declarations to image Port objects, and any malformed key aborts the build. It surfaces as BadContainerConfigurationFormatException, wrapping the offending port string.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java:240
/**
* Converts a map of exposed ports as strings to a set of {@link Port}s (e.g. {@code
* {"1000/tcp":{}}} -> {@code Port(1000, Protocol.TCP)}).
*
* @param portMap the map to convert
* @return a set of {@link Port}s
*/
@VisibleForTesting
static ImmutableSet<Port> portMapToSet(@Nullable Map<String, Map<String, String>> portMap)
throws BadContainerConfigurationFormatException {
if (portMap == null) {
return ImmutableSet.of();
}
ImmutableSet.Builder<Port> ports = new ImmutableSet.Builder<>();
for (Map.Entry<String, Map<String, String>> entry : portMap.entrySet()) {
String port = entry.getKey();
Matcher matcher = PORT_PATTERN.matcher(port);
if (!matcher.matches()) {
throw new BadContainerConfigurationFormatException(
"Invalid port configuration: '" + port + "'.");
}
int portNumber = Integer.parseInt(matcher.group("portNum"));
String protocol = matcher.group("protocol");
ports.add(Port.parseProtocol(portNumber, protocol));
}
return ports.build();
}
/**
* Converts a map of volumes strings to a set of {@link AbsoluteUnixPath}s (e.g. {@code
* {"/var/log/my-app-logs":{}}} -> {@code AbsoluteUnixPath().get("/var/log/my-app-logs")}).
*
* @param volumeMap the map to convert
* @return a set of {@link AbsoluteUnixPath}s
*/
@VisibleForTestingView on GitHub (pinned to fb949e2676)
Solutions
- Inspect the ports configuration and fix the offending key so it matches '<number>' or '<number>/<tcp|udp>' (e.g. '8080' or '8080/tcp').
- Remove unsupported syntax such as port ranges or host:container mappings; Jib ports are container-side only.
- Validate all port numbers are 1-65535 and protocols are tcp or udp before building.
Example fix
// before
containerConfig.put("ports", Map.of("8080:8080/tcp", Map.of()));
// after
containerConfig.put("ports", Map.of("8080/tcp", Map.of())); Defensive patterns
Strategy: validation
Validate before calling
// validate port spec before configuring Jib
private static final Pattern PORT_PATTERN = Pattern.compile("(?<portNum>\\d+)(?:/(?<protocol>tcp|udp))?");
for (String port : portsConfig.keySet()) {
if (!PORT_PATTERN.matcher(port).matches())
throw new IllegalArgumentException("Invalid port configuration: '" + port + "'.");
} Prevention
- Keep ports as '<number>' or '<number>/tcp|udp' strings — never ranges, mappings, or service names.
- Add a build-time check (Gradle/Maven task) that validates port keys before invoking Jib.
- Test container config generation in CI so bad values fail early.
When it happens
Trigger: Calling Jib with a containerConfiguration whose ports map contains a key that is not a valid port spec, e.g. "8080/tcp" written as "808 0", "http", "8080:8080", or a non-numeric port like "eighty".
Common situations: Hand-written jib.container.ports lists in Maven/Gradle config, copy-pasted Dockerfile EXPOSE entries with ranges (8000-8010), or YAML/JSON config where ports were given as name:value pairs instead of valid number/protocol keys.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid port configuration: '<port>'. Make sure the port is
- Invalid port range '<port>'; smaller number must come first.
- Port number '<port>' is out of usual range (1-65535).
- Invalid volume path: + volume
- octalPermissions must be a 3-digit octal number (000-777)
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/e55580c5622b7936.
Report an issue: GitHub.