>_ IzzyLab

Hands-on task

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

Network fact sheet: subnet, gateway and addresses

medium~12 min

The network diagram needs a fact sheet for the lab-net network. Write three lines in key=value format to /root/lab-net.txt:

subnet=<lab-net's subnet, address/mask>
gateway=<lab-net's gateway>
beta=<the IPv4 address of the beta container in lab-net>

Then start a container gamma from izzylab/minihttp:1 in the lab-net network with a fixed address: from the lab-net subnet, with 50 as the last octet. The beta container must be able to open http://gamma:8080/.

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 inspect
  • ipam
  • docker run --ip

Topic breakdown

Every Docker network gets a subnet and a gateway — the bridge's address on the host — from IPAM (the address manager). You can set the subnet at creation (--subnet, --gateway, --ip-range), otherwise Docker takes the next free one from its pools. All of this shows up in docker network inspect: IPAM.Config holds the subnet and gateway, Containers lists who is connected and with which addresses. A container's address is usually dynamic and changes when it's recreated; when you need a fixed one (a firewall rule, an outside client without DNS), you set it with --ip in a network with an explicit subnet. Go templates in -f pull out a single field — handy for scripts.

What's checked

  1. /root/lab-net.txt has lab-net's correct subnet
  2. /root/lab-net.txt has lab-net's correct gateway
  3. /root/lab-net.txt has beta's correct address
  4. gamma is in lab-net with a fixed address from its subnet, last octet 50
  5. beta opens http://gamma:8080/

What it looks like