The knowledge base / All cheat sheets
● Always in your toolkitAbout the project ↗

Docker published port conflict investigation cheat sheet

Find which host listener or container owns a port when Docker reports that a published port is already allocated.

Docker Engine on Linux with iproute2; rootless, remote daemon and Docker Desktop networking differ.

Updated · Docker · 6 min read

CommandWhat it does
docker context showIdentify the Docker context
docker ps --format "table {{.Names}}\t{{.Ports}}"Inspect running container ports
docker port webInspect one container mapping
sudo ss -ltnpInspect TCP listeners
docker inspect web --format "{{json .HostConfig.PortBindings}}"Inspect configured port bindings

Walkthrough

Replace 8080 and web with the actual approved port and container. Commands inspect state and do not stop processes or change port bindings.

Step 1: Identify the Docker context

docker context show

Confirm which daemon the client targets. Host socket inspection must run on the daemon host to be comparable to container port information.

Step 2: Inspect running container ports

docker ps --format "table {{.Names}}\t{{.Ports}}"

Find containers publishing the affected host port. Port mappings show configured publishing and should be interpreted alongside actual host listener information.

Step 3: Inspect one container mapping

docker port web

Replace web with the relevant running container and review its published mappings. A missing mapping on one container does not exclude another host process.

Step 4: Inspect TCP listeners

sudo ss -ltnp

Review local listening addresses, ports and process information with appropriate permissions. A wildcard binding may conflict with a more specific address depending on socket configuration.

Step 5: Inspect configured port bindings

docker inspect web --format "{{json .HostConfig.PortBindings}}"

Review the selected container host bindings without printing its full configuration. This describes the chosen container and may not identify another process holding the port.

WORKED INCIDENT

Practical case: A service cannot bind its published port

Fictional teaching scenario; observations are examples, not captured production output.

Situation

A new Docker service fails to start because its requested host TCP port is already allocated.

Investigation sequence

1. Identify the Docker context

docker context show

Confirm the Docker context and identify the corresponding daemon host.

2. Inspect running container ports

docker ps --format "table {{.Names}}\t{{.Ports}}"

Inspect published ports of running containers for the requested binding.

3. Inspect one container mapping

docker port web

Compare the affected container mapping and the host listener information.

4. Inspect TCP listeners

sudo ss -ltnp

Inspect the intended binding before coordinating an approved port change.

Example findings

Illustrative findings: an existing container already publishes the same host address and TCP port required by the new service.

Interpret the findings

The existing mapping explains the conflict in this example. Port ownership must be checked on the actual daemon host.

Verify the outcome

After the service owner approves a nonconflicting mapping, deploy through the normal process and verify application connectivity.

Escalation handoff

Share sanitized daemon context, port mapping and listener evidence with the container and host owners.

Primary references

Documented reference; examples above are teaching scenarios. Confirm behavior against your deployed version.