Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A Docker container port is not reachable from the host or network

ErrorThe PORTS column of docker ps shows 80/tcp with no host port

Short answer

A container port is closed to the outside until you publish it with -p or a ports entry. If it is published but unreachable, check the order HOST:CONTAINER, the container port number, and whether the mapping is bound to 127.0.0.1, which limits it to the Docker host.

  • Applies to Docker Engine 28, Docker Compose v2, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List what the container really publishes. An empty PORTS column means nothing is mapped.

    docker ps --format 'table {{.Names}}	{{.Ports}}'
  2. 2Match what you see, then jump to its fix

    1. 1PORTS shows only 80/tcp with no arrow and no host portThe port is not published at allFix
    2. 2PORTS shows 0.0.0.0:80->8080/tcp but the app listens on 80 insideHost and container ports are swapped, or the container port is wrongFix
    3. 3Works with curl on the Docker host, fails from another computerThe mapping is bound to 127.0.0.1, so other machines cannot reach itFix

What does the error look like?

  • The PORTS column of docker ps shows 80/tcp with no host port
  • The service answers inside the container but not from the host

Cause 1 of 3

The port is not published at all

1Check

By default none of a container's ports are exposed to the host. EXPOSE in a Dockerfile only documents the port; -P publishes exposed ports to random host ports.

docker port my-container

2Fix

Publish the port with -p HOST:CONTAINER, or a ports: entry in Compose, then recreate the container.

docker run -d -p 8080:80 nginx:alpine
# compose
# services:
#   web:
#     ports:
#       - "8080:80"

3Verify

The host port answers.

curl -I http://localhost:8080

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

Host and container ports are swapped, or the container port is wrong

1Check

The left side is the host, the right side is the container. The right side must be the port the app listens on inside the container.

docker port my-container

2Fix

Put the host port first and the app's own port second. Other containers on the same network use the container port, not the host port.

services:
  db:
    image: postgres:17
    ports:
      - "8001:5432"

3Verify

From the host use 8001; from another service use db:5432.

docker compose ps

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The mapping is bound to 127.0.0.1, so other machines cannot reach it

1Check

A mapping like 127.0.0.1:8080:80 limits access to the Docker host. With no address, Docker publishes on all interfaces.

docker port my-container

2Fix

Drop the 127.0.0.1 prefix if outside access is intended. Keep it for services that only the host should reach, and expose those through a reverse proxy.

docker run -d -p 8080:80 nginx:alpine

3Verify

The port answers from another machine.

curl -I http://SERVER_IP:8080

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Write the mapping as HOST:CONTAINER in a Compose file, quoted, and review it in code review.
  • Bind admin ports to 127.0.0.1 on purpose.
  • Remember that published ports bypass ufw rules; filter with the DOCKER-USER chain.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A dev container port does not open in the browser when Docker runs on a remote host

If your application only accepts calls from localhost, it will reject connections from published ports

Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.