>_ IzzyLab

Hands-on task

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

The service listens on 127.0.0.1 — neighbors can't reach it

medium~10 min

web calls orders at orders:8080 (network shop) and gets 502, although inside orders itself everything answers: docker exec orders wget -qO- http://127.0.0.1:8080/.

Find out why the neighbors can't reach orders and fix it. The settings of orders are in /root/orders/orders.env — fix them there and recreate orders with the same name, in the shop network, with this env file. Don't touch web.

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:
  • bind address
  • ss
  • nsenter
  • docker --env-file

Topic breakdown

Every container has its own network stack and its own lo. A service listening on 127.0.0.1 accepts connections only from inside its own container: network neighbors come to the eth0 address, and nobody listens there — Connection refused. Publishing with -p won't help either: Docker forwards the port to the container's address, not to its loopback. Hence the rule: inside a container a service listens on 0.0.0.0 (or the address of the right interface), and who gets in is decided by Docker networks and port publishing. It's handy to check who listens on what from the host: nsenter -n by the container's PID plus ss -ltn — this works even in images with no tools.

What's checked

  1. web is running, not recreated
  2. web gets an answer from orders
  3. orders is in the shop network and runs with the settings from /root/orders/orders.env

What it looks like