SnowOps Night Shift

Why does my Docker container's published port give an empty reply to every request?

docker run -p host:container sends traffic for the host port to a port inside the container, and Docker does not check that anything listens there. If the container port is wrong, the container stays Up and its logs stay quiet, but every request gets an empty reply. Compare the PORTS column of docker ps with the ports the image declares in docker image inspect. In this incident the host port was mapped to port 80 while nginx listened on 8080.

What it looks like

  • The container is Up and never restarts.
  • curl to the host port fails with an empty reply from server, not an HTTP error.
  • The server's logs show no requests at all.
  • The container was recreated recently from a run command typed by hand.

Commands that find the cause

  1. docker ps

    Running containers. In PORTS, host:port->container_port/tcp means traffic to the host port is sent to that port inside the container; a bare port/tcp is one the image exposes that nothing publishes. The published container port must be the one the app listens on.

  2. docker image inspect -f '{{json .Config.ExposedPorts}}' ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine

    The ports the image itself declares, before any run command adds to them. This is where the app inside expects traffic.

  3. curl -sS -o /dev/null -w '%{http_code}\n' http://localhost:18081/

    One request the way the storefront makes it. A number is an HTTP status; 000 with a curl error means no HTTP answer came back at all, so the request never reached a server that understood it.

  4. docker logs --tail 5 images

    What the server printed. A server that started cleanly and never logged a request tells you requests are not reaching it.

  5. docker port images

    The same mapping as PORTS, one line per published port: container port first, then the host address it is bound to.

What the evidence looked like

Recorded on a real system when this incident was captured for the game.

$ docker ps
CONTAINER ID   IMAGE                                             COMMAND                  CREATED          STATUS          PORTS                                                 NAMES
851413a6528e   ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine   "/docker-entrypoint.…"   25 seconds ago   Up 25 seconds   8080/tcp, 0.0.0.0:18081->80/tcp, [::]:18081->80/tcp   images

Root cause

The image service was recreated with host port 18081 mapped to container port 80, but nginx listens on 8080; remapping fixed it.

The fix

Recreate the container with the host port mapped to the port the app listens on:

docker rm -f images && docker run -d --name images -p 18081:8080 ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine

How to prevent it

Keep the run command or a compose file in the repo instead of retyping it. Images that run as a non-root user usually listen on a high port such as 8080: check docker image inspect before mapping.

More incident guides