>_ IzzyLab

Hands-on task

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

A container's routes via nsenter

hard~15 min

tracker stopped reaching api (both are in the ops network): tracker's /call answers 502, and docker exec tracker wget -qO- http://api:8080/ says Network is unreachable. Looks like someone "cleaned up" the routing table in tracker's network namespace.

Put back the routes Docker sets: to the ops network's subnet directly via eth0, and the default route via the ops network's gateway. Don't restart, recreate or reconnect the container to the network: it holds an event queue in memory, and open connections must not be dropped.

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:
  • nsenter
  • ip route
  • network namespace
  • capabilities

Topic breakdown

A container's network is an ordinary kernel network namespace: its own interfaces, addresses and routing table. When connecting a container to a network, Docker puts into it the eth0 interface (one end of a veth pair), an address, a route to the network's subnet via eth0 and a default route via the gateway — the bridge's address on the host. None of this can be changed from inside the container: Docker doesn't give its processes CAP_NET_ADMIN, and even root inside gets Operation not permitted. But the host's root can enter the container's namespace: nsenter -t <PID> -n runs a host command with the container's network — that's how you inspect and fix the network of a live container without restarting it or adding tools to the image.

What's checked

  1. tracker is running, not restarted, recreated or reconnected to the network
  2. api answers from tracker
  3. tracker has a route to the ops subnet via eth0
  4. tracker has a default route via the ops network's gateway

What it looks like