>_ IzzyLab

Hands-on task

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

Segmentation: the storefront can't see the database

medium~15 min

An application of three izzylab/minihttp:1 containers: web calls api (UPSTREAM=api:8080), api calls db (UPSTREAM=db:8080). Right now all three are in one network flat, and from web you can get straight to the database — an audit won't let that pass.

Split the network:

  • network front: web and api;
  • network back: api and db;
  • web only in front, db only in back, api in both;
  • the chain web → api → db works, and from web you can't reach db either by name or by IP.

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
  • network segmentation
  • multi-network container

Topic breakdown

A Docker network is a separate bridge on the host with its own subnet. Containers in the same network see each other directly, and between different networks Docker installs iptables rules (the DOCKER-ISOLATION-* chains) that cut traffic from bridge to bridge — even by IP. That's why segmentation is done with networks: frontend and backend in one, backend and database in another. The service in the middle gets both networks: it gets a second interface (eth1) with an address from the second subnet, and each network's built-in DNS tells it about that network's neighbors. Then a compromised storefront can't talk to the database directly — only through the API, which validates requests.

What's checked

  1. web is connected only to front
  2. api is connected to front and back — and nothing else
  3. db is connected only to back
  4. web reaches api
  5. api reaches db
  6. From web, db can't be reached — neither by name nor by IP

What it looks like