{"record":{"id":"0997e42577468d0c","repo":"docker/compose","slug":"no-port-s-for-container-s-s","errorCode":null,"errorMessage":"no port %s for container %s: %s","messagePattern":"no port (.+?) for container (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/compose/port.go","lineNumber":54,"sourceCode":"\t\tif p.PrivatePort == port && p.Type == options.Protocol {\n\t\t\treturn p.IP.String(), int(p.PublicPort), nil\n\t\t}\n\t}\n\treturn \"\", 0, portNotFoundError(options.Protocol, port, ctr)\n}\n\nfunc portNotFoundError(protocol string, port uint16, ctr container.Summary) error {\n\tformatPort := func(protocol string, port uint16) string {\n\t\treturn fmt.Sprintf(\"%d/%s\", port, protocol)\n\t}\n\n\tvar containerPorts []string\n\tfor _, p := range ctr.Ports {\n\t\tcontainerPorts = append(containerPorts, formatPort(p.Type, p.PrivatePort))\n\t}\n\n\tname := strings.TrimPrefix(ctr.Names[0], \"/\")\n\treturn fmt.Errorf(\"no port %s for container %s: %s\", formatPort(protocol, port), name, strings.Join(containerPorts, \", \"))\n}\n","sourceCodeStart":36,"sourceCodeEnd":56,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/port.go#L36-L56","documentation":"The port command resolves a numeric service port/protocol to the container's actual published binding by scanning the container's port list. If no entry matches protocol/port, compose reports the requested port plus every port the container actually has, making mismatches self-explanatory.","triggerScenarios":"docker compose port <svc> <port> [--protocol udp] where the container exposes no such private port: wrong port number, wrong protocol, service scaled to 0 or not started, or port only defined on another service.","commonSituations":"Scripting against a port the service maps dynamically (no fixed host port); typo in port number; querying before the container is up; forgetting a port is UDP-only while querying tcp.","solutions":["Compare against the ports listed in the error itself — they are the container's real ports","Fix the compose file to expose the intended port, or query one of the listed ports","Pass --protocol udp when the target port is UDP","Ensure the service is running (docker compose ps) before resolving ports"],"exampleFix":"# before (compose.yaml)\nservices:\n  web:\n    ports: [\"8080:80\"]\n# docker compose port web 3000 -> no port 3000\n\n# after\nservices:\n  web:\n    ports: [\"8080:3000\"]\n# docker compose port web 3000 -> 0.0.0.0:8080","handlingStrategy":"validation","validationCode":"// resolve only ports the service actually declares\nsvc := project.Services[name]\nfor _, p := range svc.Ports {\n    if p.Target == wantPort && string(p.Protocol) == wantProto {\n        // safe to call Port()\n    }\n}","typeGuard":null,"tryCatchPattern":"addr, err := composeService.Port(ctx, project, service, port, protocol)\nif err != nil && strings.HasPrefix(err.Error(), \"no port \") {\n    // message lists the container's real ports; fall back to those or skip\n}","preventionTips":["Declare fixed container-side ports (target) so lookups are deterministic","Check `docker compose ps --format json` for actual port mappings before scripting against them","Remember the --protocol flag for UDP ports"],"tags":["port","networking","cli","ports"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}