{"record":{"id":"0c92648e2f566a80","repo":"slimtoolkit/slim","slug":"slim-error-missing-comms-ports","errorCode":null,"errorMessage":"slim: error => missing comms ports","messagePattern":"slim: error => missing comms ports","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/inspectors/container/container_inspector.go","lineNumber":755,"sourceCode":"\tif err := i.APIClient.StartContainer(i.ContainerID, nil); err != nil {\n\t\treturn err\n\t}\n\n\tinspectContainerOpts := dockerapi.InspectContainerOptions{ID: i.ContainerID, Size: true}\n\tif i.ContainerInfo, err = i.APIClient.InspectContainerWithOptions(inspectContainerOpts); err != nil {\n\t\treturn err\n\t}\n\n\tif i.ContainerInfo.NetworkSettings == nil {\n\t\treturn fmt.Errorf(\"slim: error => no network info\")\n\t}\n\n\tif hCfg := i.ContainerInfo.HostConfig; hCfg != nil && !i.isHostNetworked() {\n\t\tlogger.Debugf(\"container HostConfig.NetworkMode => %s len(ports)=%d\",\n\t\t\thCfg.NetworkMode, len(i.ContainerInfo.NetworkSettings.Ports))\n\n\t\tif len(i.ContainerInfo.NetworkSettings.Ports) < len(commsExposedPorts) {\n\t\t\treturn fmt.Errorf(\"slim: error => missing comms ports\")\n\t\t}\n\t}\n\n\tlogger.Debugf(\"container NetworkSettings.Ports => %#v\", i.ContainerInfo.NetworkSettings.Ports)\n\n\ti.setAvailablePorts(hostProbePorts)\n\n\tif i.PrintState {\n\t\ti.xc.Out.Info(\"container\",\n\t\t\tovars{\n\t\t\t\t\"status\": \"running\",\n\t\t\t\t\"name\":   containerInfo.Name,\n\t\t\t\t\"id\":     i.ContainerID,\n\t\t\t})\n\t}\n\n\tif err = i.initContainerChannels(); err != nil {\n\t\treturn err","sourceCodeStart":737,"sourceCodeEnd":773,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/inspectors/container/container_inspector.go#L737-L773","documentation":"After inspecting the container, docker-slim checks that the container's reported NetworkSettings.Ports contains at least as many entries as the communication ports (commsExposedPorts, derived from the target's ExposedPorts config). If the engine reports fewer mapped ports than expected, the inspector cannot reach the app, so it fails with this error. It only applies when the container is not host-networked.","triggerScenarios":"RunContainer on a non-host-networked container where len(NetworkSettings.Ports) < len(commsExposedPorts) — i.e. some of the ports declared via --expose/EXPOSE or slim's --http-probe flags were not actually published or reported by the engine.","commonSituations":"Using --network host assumptions with a bridge container; image EXPOSE metadata mismatching actual listening ports; docker run overriding port publishing; Docker versions reporting ports differently.","solutions":["Confirm the target image EXPOSEs or the slim command exposes all ports the app actually uses (e.g. --expose 8080).","Check docker inspect <container> NetworkSettings.Ports to see which ports the engine reports.","Avoid --network host conflicts; ensure the container runs on a normal bridge network or adjust slim flags accordingly.","Publish the missing ports explicitly (docker run -p 8080:8080) if the app needs inbound access."],"exampleFix":"// before: image lacks exposed ports\nFROM golang\nCMD [\"/app\"]\n// after\nFROM golang\nEXPOSE 8080\nCMD [\"/app\"]\n// or run slim with: slim build --expose 8080 -- <image>","handlingStrategy":"validation","validationCode":"info, _ := client.InspectContainerWithOptions(opts)\nif info.NetworkSettings != nil && len(info.NetworkSettings.Ports) < len(expectedExposedPorts) {\n    // fix EXPOSE/-p flags before running slim\n    fmt.Println(\"container reports fewer ports than expected\")\n}","typeGuard":"func hasAllCommsPorts(info *dockertypes.ContainerJSON, want int) bool {\n    return info != nil && info.NetworkSettings != nil && len(info.NetworkSettings.Ports) >= want\n}","tryCatchPattern":"if err := runSlim(); err != nil && strings.Contains(err.Error(), \"missing comms ports\") {\n    log.Fatal(\"add --expose <port> for every port your app listens on, then re-run slim\")\n}","preventionTips":["Always mirror every app listening port in the image EXPOSE directive or slim's --expose flag.","Run docker inspect on the target container to confirm reported Ports before slimming.","Don't mix host networking expectations with bridge-networked containers."],"tags":["docker","ports","network"],"backgroundTag":"missing-exposed-ports","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}