docker/cli · warning

no public port ' ' published for

Error message

no public port '%s' published for %s

What it means

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.

Solutions

  1. List all published ports first: docker port CONTAINER (no port arg)
  2. Check the create/run flags included -p for that port
  3. Specify the protocol explicitly if non-tcp: docker port CONTAINER 8080/udp
  4. Inspect the container: docker inspect --format '{{json .NetworkSettings.Ports}}' CONTAINER

Example fix

# before
docker port myctr 8080   # nothing published on 8080
# after
docker run -p 8080:80 --name myctr img  # publish first, then docker port myctr 8080 works
Defensive patterns

Strategy: try-catch

Validate before calling

// Before querying a specific port, confirm it's published.
inspect, err := cli.ContainerInspect(ctx, name)
if err != nil {
    return err
}
key := "8080/tcp"
if _, ok := inspect.NetworkSettings.Ports[nat.Port(key)]; !ok {
    return fmt.Errorf("no mapping for %s; published: %v", key, inspect.NetworkSettings.Ports)
}

Try / catch

if _, err := cli.ContainerInspect(ctx, name); err != nil {
    // handle inspect failure
}
// treat 'no public port' as a non-fatal empty result rather than an error

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/3010479d5ef2098a. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/container/port.go:69

//
// TODO(thaJeztah): currently this defaults to show the TCP port if no
// proto is specified. We should consider changing this to "any" protocol
// for the given private port.
func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) error {
	c, err := dockerCli.Client().ContainerInspect(ctx, opts.container, client.ContainerInspectOptions{})
	if err != nil {
		return err
	}

	var out []string
	if opts.port != "" {
		port, err := network.ParsePort(opts.port)
		if err != nil {
			return err
		}
		frontends, exists := c.Container.NetworkSettings.Ports[port]
		if !exists || len(frontends) == 0 {
			return fmt.Errorf("no public port '%s' published for %s", opts.port, opts.container)
		}
		for _, frontend := range frontends {
			out = append(out, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort))
		}
	} else {
		for from, frontends := range c.Container.NetworkSettings.Ports {
			for _, frontend := range frontends {
				out = append(out, fmt.Sprintf("%s -> %s", from, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort)))
			}
		}
	}

	if len(out) > 0 {
		sort.Slice(out, func(i, j int) bool {
			return sortorder.NaturalLess(out[i], out[j])
		})
		_, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(out, "\n"))
	}

View on GitHub (pinned to 4f84911bfe)