>_ IzzyLab

Hands-on task

This task is step 6 of the course “Docker networking”

A network with no way out: --internal

medium~12 min

ledger stores transactions, worker processes them (UPSTREAM=ledger:8080); both are in the vault network. Security requires that the vault network has no way out to the outside world. In the lab the outside world is played by the service http://198.51.100.10:9099/ on the server — right now ledger can reach it: docker exec ledger wget -qO- http://198.51.100.10:9099/.

Make vault an internal Docker network so that:

  • ledger is connected only to vault, and worker is connected to it too;
  • worker still reaches ledger;
  • the outside service becomes unreachable from ledger (don't touch the service itself).

You may reconnect the containers or recreate them with the same names and settings.

The lab has its own Docker with no internet access; the images are already loaded: izzylab/minihttp:1, alpine:3.21, busybox:1.36, nginx:1.27-alpine. izzylab/minihttp is a tiny HTTP service on port 8080: GET / answers <NAME> ok, GET /call itself goes to http://<UPSTREAM>/ and answers <NAME> -> <the neighbor's reply> (or 502), GET /env shows its settings. It is configured with the environment variables NAME, PORT, BIND (the address it listens on) and UPSTREAM.

What you'll practise:
  • docker network --internal
  • egress

Topic breakdown

A regular Docker network lets containers out: a container has a default route through the gateway — the bridge's address on the host — and the host does NAT (MASQUERADE) into its own network. A network created with --internal has no default route: containers see only their own subnet, Docker sets up no NAT for it and forbids forwarding from it to other interfaces. Containers inside still talk to each other and find each other by name. This is how databases and queues that don't need the internet are hidden: even a compromised process can't send data out. The flag is set only when the network is created, so the network is recreated and the containers are connected again.

What's checked

  1. The vault network is internal
  2. ledger is connected only to vault
  3. worker is connected to vault
  4. worker reaches ledger
  5. The outside service is unreachable from ledger
  6. The outside service on the server works

What it looks like