docker/compose · warning

no port %s for container %s: %s

Error message

no port %s for container %s: %s

What it means

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.

Source

Thrown at pkg/compose/port.go:54

		if p.PrivatePort == port && p.Type == options.Protocol {
			return p.IP.String(), int(p.PublicPort), nil
		}
	}
	return "", 0, portNotFoundError(options.Protocol, port, ctr)
}

func portNotFoundError(protocol string, port uint16, ctr container.Summary) error {
	formatPort := func(protocol string, port uint16) string {
		return fmt.Sprintf("%d/%s", port, protocol)
	}

	var containerPorts []string
	for _, p := range ctr.Ports {
		containerPorts = append(containerPorts, formatPort(p.Type, p.PrivatePort))
	}

	name := strings.TrimPrefix(ctr.Names[0], "/")
	return fmt.Errorf("no port %s for container %s: %s", formatPort(protocol, port), name, strings.Join(containerPorts, ", "))
}

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Compare against the ports listed in the error itself — they are the container's real ports
  2. Fix the compose file to expose the intended port, or query one of the listed ports
  3. Pass --protocol udp when the target port is UDP
  4. Ensure the service is running (docker compose ps) before resolving ports

Example fix

# before (compose.yaml)
services:
  web:
    ports: ["8080:80"]
# docker compose port web 3000 -> no port 3000

# after
services:
  web:
    ports: ["8080:3000"]
# docker compose port web 3000 -> 0.0.0.0:8080
Defensive patterns

Strategy: validation

Validate before calling

// resolve only ports the service actually declares
svc := project.Services[name]
for _, p := range svc.Ports {
    if p.Target == wantPort && string(p.Protocol) == wantProto {
        // safe to call Port()
    }
}

Try / catch

addr, err := composeService.Port(ctx, project, service, port, protocol)
if err != nil && strings.HasPrefix(err.Error(), "no port ") {
    // message lists the container's real ports; fall back to those or skip
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/0997e42577468d0c. Report an issue: GitHub.