{"record":{"id":"e55580c5622b7936","repo":"GoogleContainerTools/jib","slug":"invalid-port-configuration-port","errorCode":null,"errorMessage":"Invalid port configuration: '\" + port + \"'.","messagePattern":"Invalid port configuration: '\" \\+ port \\+ \"'\\.","errorType":"validation","errorClass":"BadContainerConfigurationFormatException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java","lineNumber":240,"sourceCode":"  /**\n   * Converts a map of exposed ports as strings to a set of {@link Port}s (e.g. {@code\n   * {\"1000/tcp\":{}}} -> {@code Port(1000, Protocol.TCP)}).\n   *\n   * @param portMap the map to convert\n   * @return a set of {@link Port}s\n   */\n  @VisibleForTesting\n  static ImmutableSet<Port> portMapToSet(@Nullable Map<String, Map<String, String>> portMap)\n      throws BadContainerConfigurationFormatException {\n    if (portMap == null) {\n      return ImmutableSet.of();\n    }\n    ImmutableSet.Builder<Port> ports = new ImmutableSet.Builder<>();\n    for (Map.Entry<String, Map<String, String>> entry : portMap.entrySet()) {\n      String port = entry.getKey();\n      Matcher matcher = PORT_PATTERN.matcher(port);\n      if (!matcher.matches()) {\n        throw new BadContainerConfigurationFormatException(\n            \"Invalid port configuration: '\" + port + \"'.\");\n      }\n\n      int portNumber = Integer.parseInt(matcher.group(\"portNum\"));\n      String protocol = matcher.group(\"protocol\");\n      ports.add(Port.parseProtocol(portNumber, protocol));\n    }\n    return ports.build();\n  }\n\n  /**\n   * Converts a map of volumes strings to a set of {@link AbsoluteUnixPath}s (e.g. {@code\n   * {\"/var/log/my-app-logs\":{}}} -> {@code AbsoluteUnixPath().get(\"/var/log/my-app-logs\")}).\n   *\n   * @param volumeMap the map to convert\n   * @return a set of {@link AbsoluteUnixPath}s\n   */\n  @VisibleForTesting","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java#L222-L258","documentation":"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.","triggerScenarios":"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\".","commonSituations":"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.","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."],"exampleFix":"// before\ncontainerConfig.put(\"ports\", Map.of(\"8080:8080/tcp\", Map.of()));\n// after\ncontainerConfig.put(\"ports\", Map.of(\"8080/tcp\", Map.of()));","handlingStrategy":"validation","validationCode":"// validate port spec before configuring Jib\nprivate static final Pattern PORT_PATTERN = Pattern.compile(\"(?<portNum>\\\\d+)(?:/(?<protocol>tcp|udp))?\");\nfor (String port : portsConfig.keySet()) {\n    if (!PORT_PATTERN.matcher(port).matches())\n        throw new IllegalArgumentException(\"Invalid port configuration: '\" + port + \"'.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["docker","container-config","ports","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}