World map

 

BM: Baca dalam Bahasa Melayu

World D3: Lockers & Phone Lines

Publish, expose, host and none

You will learn: which ports your laptop can reach, and the host and none network modes.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

docker ps shows web with 80/tcp in PORTS. curl localhost:8080 fails: Couldn't connect to server. Docker transcript: $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 36f63acc8211 nginx:1.30-alpine "/docker-entrypoint.…" 3 seconds ago Up 3 seconds 80/tcp web $ curl localhost:8080 curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB · in use

1 containers (1 running), 2 images, 0 lockers.

web is up. Its PORTS column says 80/tcp. Yet curl says Couldn't connect to server. Plain words: no hatch is open on your laptop.

Watch

Open a hatch from laptop port 8080 to web port 80. Leave db alone.

Tap a laptop port, then a container port.

Your laptop

web

db

$ docker run -d --name web nginx:1.30-alpine$ docker run -d --name db postgres:18-alpine

To publish a port (-p 8080:80) opens a port mapping: The order hatch: a door from a port on your computer to a port in the container. on your laptop. EXPOSE 80 in a recipe only writes the port on the label.

Predict

db shows 5432/tcp, with no -p. Who can reach it?

Pick one answer.

Try it

Give web a hatch on 8080. A box can’t get a new hatch later, so make it again.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB · in use

1 containers (1 running), 2 images, 0 lockers.

Watch

Each box gets a line type. The default is bridge. host shares your laptop’s own line. none has no line at all. Sort them.

Drag a card into a box. Or tap the card, then tap the box.

        Check

        host mode prints: WARNING: Published ports are discarded when using host network mode. With none, ping says: Network unreachable. Docker transcript: $ docker run -d --name hostbox --network host -p 8082:80 alpine:3.22 sleep 300 WARNING: Published ports are discarded when using host network mode 56b39ebfbae84e54a3f5dd2ba3105146341fc725083c071f6dc2b543e2d509fe $ docker run --rm --network none alpine:3.22 ping -c 1 8.8.8.8 PING 8.8.8.8 (8.8.8.8): 56 data bytes ping: sendto: Network unreachable

        Your laptop~

        • No open hatches

        Lunchboxes (containers)

        • webrunning
          from nginx:1.30-alpine

        Frozen packs (images)

        • alpine:3.221 layers · 12.9MB
        • nginx:1.30-alpine8 layers · 93.5MB · in use

        1 containers (1 running), 2 images, 0 lockers.

        Real words from Docker: host mode discards -p. With none, Network unreachable: the box has no line out.

        You did it!

        You can now choose which ports your laptop can reach.

        Go deeper (optional)

        -p 8080:80 listens on every network card, so your Wi-Fi neighbours may reach it too. -p 127.0.0.1:8080:80 keeps the hatch for your laptop only. -P opens a random hatch for each exposed port. On Docker Desktop, host mode needs a recent version; check the docs.

        Real rep (optional):

        Real mission

        1. docker run -d --name web -p 127.0.0.1:8080:80 nginx:1.30-alpine
        2. docker port web
        3. docker run --rm --network none alpine:3.22 ping -c 1 8.8.8.8
        4. docker rm -f web

        0 of 4 steps done · Your ticks are saved.