World map

 

BM: Baca dalam Bahasa Melayu

World D3: Lockers & Phone Lines

Phone lines: your own network

You will learn: to put containers on your own network, so they can call each other.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

web and db both run. web pings db by name and gets: ping: bad address 'db'. Docker transcript: $ docker exec web ping -c 1 db ping: bad address 'db'

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine
  • dbrunning
    from postgres:18-alpine no name → /var/lib/postgresql

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB · in use
  • postgres:18-alpine9 layers · 433MB · in use

Lockers (volumes)

  • 19c922aa7052… (no name)24 files · used by db

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

web needs to call db. Both run on your laptop. Yet: ping: bad address 'db'. Plain words: web has no phone book with db in it.

Watch

Tap the phone line you made.

0 of 1 found

A network (your own): A phone line you make with docker network create. Containers on it call each other by name. is a phone line between lunchboxes. docker network create shopnet makes your own line. Docker made the other three for you.

Try it

Make the shopnet line. Plug web and db into it.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine
  • dbrunning
    from postgres:18-alpine no name → /var/lib/postgresql

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB · in use
  • postgres:18-alpine9 layers · 433MB · in use

Lockers (volumes)

  • 19c922aa7052… (no name)24 files · used by db

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

Predict

cache starts with a plain docker run, no --network. Can it call menu, which is on shopnet?

Pick one answer.

Watch

cache can't find menu. After docker network connect shopnet cache, the menu page title comes back. Docker transcript: $ docker exec cache wget -qO- http://menu wget: bad address 'menu' $ docker network connect shopnet cache $ docker exec cache sh -c "wget -qO- http://menu | grep title" <title>Welcome to nginx!</title>

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • menurunning
    from nginx:1.30-alpine shopnet
  • cacherunning
    from alpine:3.22

Frozen packs (images)

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

Phone lines (networks)

  • shopnetmenu

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

docker network connect plugs a running box into a line. No restart needed. Now cache can call menu.

Check

db is on shopnet. Which boxes can call it by name?

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

      You did it!

      You can now give your containers their own phone line.

      Go deeper (optional)

      The default bridge has no names, and every box lands on it. Your own network has names, and only invited boxes. docker network inspect shopnet lists who is plugged in. docker network disconnect unplugs a box.

      Real rep (optional):

      Real mission

      1. docker network create practice-net
      2. docker run -d --name menu --network practice-net nginx:1.30-alpine
      3. docker run --rm --network practice-net alpine:3.22 wget -qO- http://menu
      4. docker rm -f menu && docker network rm practice-net

      0 of 4 steps done · Your ticks are saved.