A dev container port does not open in the browser when Docker runs on a remote host
The port shows in the Forwarded Ports list but the page never loadsShort answer
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. Check each in that order.
Fix it fast
1Find out which cause you have
Inside the dev container terminal, see which address the app listens on. 127.0.0.1 means published ports cannot reach it; 0.0.0.0 or [::] means they can.
ss -ltn2Match what you see, then jump to its fix
- 1
ss shows 127.0.0.1:3000 (not 0.0.0.0:3000) and a published port gets no answerThe app only listens on localhost inside the containerFix - 2
VS Code reports a different local port than the one in your app, for example 3000 mapped to 4123You are using the container port, not the mapped localhost portFix - 3
appPort or the Compose ports list shows the new value in the file, but the old mapping is still activeA published port was changed but the container was not rebuiltFix
- 1
What does the error look like?
The port shows in the Forwarded Ports list but the page never loadsIf your application only accepts calls from localhost, it will reject connections from published portsPort 3000 in the container opens on a different localhost port such as 4123
Cause 1 of 3
The app only listens on localhost inside the container
1Check
The Dev Containers docs say a published port acts like a network connection, so an app that only accepts calls from localhost rejects it. Forwarded ports appear to the app as localhost, so forwarding still works.
ss -ltn | grep 30002Fix
Either bind the app to all interfaces, or use forwardPorts instead of publishing. Add it to devcontainer.json, then reload the window.
// .devcontainer/devcontainer.json
{
"forwardPorts": [3000]
}3Verify
Open the localhost address VS Code lists for the port.
curl -I http://localhost:3000Confirmed by code.visualstudio.com
Cause 2 of 3
You are using the container port, not the mapped localhost port
1Check
VS Code shows the localhost port to use in a notification and in the Forwarded Ports section of the Remote Explorer. It can differ from the container port.
# VS Code: open the Remote Explorer and read Forwarded Ports2Fix
Open the address shown there, not the port number from the app's own log.
# example only: container port 3000 mapped to local 4123
curl -I http://localhost:41233Verify
The response comes from your app.
curl -I http://localhost:4123Confirmed by code.visualstudio.com
Cause 3 of 3
A published port was changed but the container was not rebuilt
1Check
The docs list appPort in devcontainer.json and a ports list in docker-compose.yml as the two ways to publish a port, and tell you to rebuild afterwards.
docker ps --format '{{.Names}} {{.Ports}}'2Fix
Run Dev Containers: Rebuild Container from the Command Palette. For forwarded ports, reload or reopen the window after editing forwardPorts.
// devcontainer.json
"appPort": [ 3000, "8921:5000" ]3Verify
The docker ps output now lists the new mapping.
docker ps --format '{{.Names}} {{.Ports}}'Confirmed by code.visualstudio.com
How do I stop it coming back?
- Prefer forwardPorts for development, and publish a port only when another machine must reach it.
- Run Docker on the SSH host and connect with Remote - SSH, then reopen in the container, so the setup matches the documented one.
- Write the port numbers in devcontainer.json and not only in a manual Forward a Port action, so they survive a rebuild.
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
Docker build fails with apk: not found in a Python or Ubuntu image
/bin/sh: 1: apk: not found
apk is the package manager of Alpine Linux only.
2 causes, each with a fix