>_ IzzyLab

Hands-on task

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

A sidecar in someone else's network namespace

medium~12 min

legacy is a contractor's service in the app network: it listens only on 127.0.0.1:8080 inside its container, and that can't be fixed — you may not touch the image or the settings, and the container must not be recreated. Its network neighbors (for example, client) can't reach it.

A proxy config is ready at /root/edge/default.conf: nginx listens on port 8088 and passes requests on to 127.0.0.1:8080. Start a container edge from nginx:1.27-alpine next to it with this config (in place of /etc/nginx/conf.d/default.conf) so that it shares the network namespace of legacy. Then they have a common 127.0.0.1, and client can open http://legacy:8088/.

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:
  • sidecar
  • docker network container
  • nginx proxy

Topic breakdown

A network namespace doesn't have to belong to one container. With --network container:<name> a new container joins the namespace of a running one: they share interfaces, addresses, the routing table and 127.0.0.1, so they talk over loopback like two processes on one machine and can't both take the same port. The rest of the isolation (files, processes) stays separate. This is the sidecar pattern: a proxy, a log collector or an mTLS agent is placed next to a service without changing the service itself. That's exactly how a Kubernetes pod works — all of a pod's containers live in the network namespace of one helper pause container.

What's checked

  1. legacy is running, not recreated or restarted
  2. edge from nginx:1.27-alpine runs in legacy's network namespace
  3. From client, http://legacy:8088/ is answered by legacy

What it looks like