{"record":{"id":"3010479d5ef2098a","repo":"docker/cli","slug":"no-public-port-s-published-for-s","errorCode":null,"errorMessage":"no public port '%s' published for %s","messagePattern":"no public port '(.+?)' published for (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/command/container/port.go","lineNumber":69,"sourceCode":"//\n// TODO(thaJeztah): currently this defaults to show the TCP port if no\n// proto is specified. We should consider changing this to \"any\" protocol\n// for the given private port.\nfunc runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) error {\n\tc, err := dockerCli.Client().ContainerInspect(ctx, opts.container, client.ContainerInspectOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar out []string\n\tif opts.port != \"\" {\n\t\tport, err := network.ParsePort(opts.port)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfrontends, exists := c.Container.NetworkSettings.Ports[port]\n\t\tif !exists || len(frontends) == 0 {\n\t\t\treturn fmt.Errorf(\"no public port '%s' published for %s\", opts.port, opts.container)\n\t\t}\n\t\tfor _, frontend := range frontends {\n\t\t\tout = append(out, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort))\n\t\t}\n\t} else {\n\t\tfor from, frontends := range c.Container.NetworkSettings.Ports {\n\t\t\tfor _, frontend := range frontends {\n\t\t\t\tout = append(out, fmt.Sprintf(\"%s -> %s\", from, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort)))\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(out) > 0 {\n\t\tsort.Slice(out, func(i, j int) bool {\n\t\t\treturn sortorder.NaturalLess(out[i], out[j])\n\t\t})\n\t\t_, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(out, \"\\n\"))\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/port.go#L51-L87","documentation":"Thrown by runPort when the user queries a specific private port (docker port CONTAINER PRIVATE_PORT) but that port has no entries in the container's NetworkSettings.Ports map, or the entries slice is empty. This means no -p publish mapping exists for that port/proto.","triggerScenarios":"Running `docker port myctr 8080` when the container was created without -p 8080 or with a different protocol. network.ParsePort succeeded but the key is absent or has zero frontends.","commonSituations":"Querying the wrong port number; port published under a different protocol (tcp vs udp) than defaulted; container created with --network host (no port mapping); inspecting a container that failed to start its port publisher.","solutions":["List all published ports first: docker port CONTAINER (no port arg)","Check the create/run flags included -p for that port","Specify the protocol explicitly if non-tcp: docker port CONTAINER 8080/udp","Inspect the container: docker inspect --format '{{json .NetworkSettings.Ports}}' CONTAINER"],"exampleFix":"# before\ndocker port myctr 8080   # nothing published on 8080\n# after\ndocker run -p 8080:80 --name myctr img  # publish first, then docker port myctr 8080 works","handlingStrategy":"try-catch","validationCode":"// Before querying a specific port, confirm it's published.\ninspect, err := cli.ContainerInspect(ctx, name)\nif err != nil {\n    return err\n}\nkey := \"8080/tcp\"\nif _, ok := inspect.NetworkSettings.Ports[nat.Port(key)]; !ok {\n    return fmt.Errorf(\"no mapping for %s; published: %v\", key, inspect.NetworkSettings.Ports)\n}","typeGuard":null,"tryCatchPattern":"if _, err := cli.ContainerInspect(ctx, name); err != nil {\n    // handle inspect failure\n}\n// treat 'no public port' as a non-fatal empty result rather than an error","preventionTips":["In automation, query all ports (no port arg) and match programmatically instead of asserting a single port"],"tags":["docker","port","network","inspect"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}