>_ IzzyLab

Hands-on task

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

The host network and the none network

medium~10 min

Two containers need to move to special network modes:

  • agent (izzylab/minihttp:1, NAME=agent, PORT=9100) is a metrics exporter. Monitoring expects it right in the server's network: curl http://127.0.0.1:9100/ on the server answers agent ok, and without publishing ports (-p) — the container runs in the host's network namespace;
  • crunch (busybox:1.36, an endless sleep loop) processes exports and needs no network at all: there must be no network address inside except loopback on lo.

Right now both are in the default network. Recreate them with the same names, images 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 host
  • docker network none

Topic breakdown

Besides bridges, Docker has two special network modes. --network host creates no network namespace for the container at all: the process lives in the host's network, sees its interfaces and listens on ports right on it — with no NAT, docker-proxy or -p. Metrics exporters, network agents and services that care about speed or real client addresses run this way; the price is no isolation and possible port conflicts with the host. --network none is the opposite: the container has its own namespace, but there's only lo in it. Such a container neither needs nor has access to any network — good protection for batch file processing and building untrusted code.

What's checked

  1. agent runs in the host network
  2. On the server, http://127.0.0.1:9100/ is answered by agent
  3. crunch from busybox:1.36 runs with no network
  4. Inside crunch, addresses are only on lo

What it looks like