Docker & Setup
The minimal server, the production-shaped edge, the lab CA, and the lab profile
Everything in this module lives in nginx/ in the repository.
The minimal setup
services:
nginx:
image: nginx:1.30.5
ports: ["8090:80"]
volumes: ["./html:/usr/share/nginx/html:ro"]docker compose up -d
curl -s localhost:8090 | head -5The official image's default config serves /usr/share/nginx/html. That's
a working web server in four lines, and it's the only part of this module
without TLS.
The production-shaped edge
docker compose down
docker compose -f compose_prod.yaml up -d --build
docker exec nginx nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful| What | Where |
|---|---|
| HTTPS site and API | https://localhost:8443 |
HTTP (redirects; /healthz answers) | http://localhost:8090 |
Admin area (admin / admin123) | https://localhost:8443/admin/ |
| Metrics | http://localhost:9113/metrics |
The lab CA
scripts/certs.sh runs once in the certs container. It creates a
certificate authority, then a server certificate signed by it for
localhost, nginx and 127.0.0.1. Clients that trust ca.crt trust
the server, exactly as browsers trust public CAs.
docker cp nginx:/etc/nginx/certs/ca.crt ./ca.crt
curl --cacert ca.crt https://localhost:8443/api/whoami
{"instance": "app-1", "path": "/api/whoami", "peer": "172.30.0.5", "host": "localhost",
"x_real_ip": "172.30.0.1", "x_forwarded_proto": "https", ...}The first version of the CA worked with curl and failed in Python:
"CA cert does not include key usage extension." Python 3.13 verifies
certificates in strict mode (as recent browsers do), which requires the
CA to declare basicConstraints=critical,CA:TRUE and
keyUsage=keyCertSign. A certificate that "works in curl" can still be
wrong. The script now adds the extensions, covered in the
TLS lesson.
The stub_status endpoint first answered the exporter with 403. Its
allow 172.16.0.0/12 rule assumed Docker's usual address range, but
OrbStack had given the network 192.168.158.0/24. The compose file now
pins the subnet to 172.30.0.0/24 and the rules allow exactly that. IP
rules are only as good as your knowledge of the addresses.
The lab profile
docker compose -f compose_prod.yaml --profile labs build labs
docker compose -f compose_prod.yaml run --rm labs python load_balancing.pyThe labs use httpx (with HTTP/2) and trust only the lab CA. They mount
the Docker socket so the failure labs can stop, pause and move app
containers, and like every module's labs, they have no depends_on.
Lab
- Start the minimal stack and request a file that doesn't exist. What does the 404 page reveal?
- Start the production stack and request
/api/whoamiten times with curl. Which instances answer? - Request
http://localhost:8090/api/whoamiwithcurl -i. Where does it send you?