A Docker container port is not reachable from the host or network
The PORTS column of docker ps shows 80/tcp with no host portShort 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.
Fix it fast
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}}'2Match what you see, then jump to its fix
- 1
PORTS shows only 80/tcp with no arrow and no host portThe port is not published at allFix - 2
PORTS 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
Works with curl on the Docker host, fails from another computerThe mapping is bound to 127.0.0.1, so other machines cannot reach itFix
- 1
What does the error look like?
The PORTS column of docker ps shows 80/tcp with no host portThe 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-container2Fix
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:8080Confirmed by docs.docker.com
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-container2Fix
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 psConfirmed by docs.docker.com
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-container2Fix
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:alpine3Verify
The port answers from another machine.
curl -I http://SERVER_IP:8080Confirmed by docs.docker.com
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
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
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