Lesson 13.08 · Phase 13 · Production Agents
Deploying with Docker
A container is restarted, rescheduled and replaced as a matter of routine. Build the image so that's safe: settings from the environment, no secrets inside, a non-root user, and a process that hears SIGTERM and finishes what it started.
Learning objectives
- Load all configuration from the environment, validate it at startup, fail fast with every problem listed, and redact secrets in logs.
- Write a Dockerfile, .dockerignore and compose.yaml for an agent service: pinned base, non-root user, exec-form CMD, health check, no baked-in secrets, and a grace period longer than the drain.
- Handle SIGTERM: stop accepting, report not-ready, finish in-flight runs within the grace period, then exit, and prove it against a real process.
- Lint deploy files for the mistakes that cause outages and leaks.
The agent service from Lesson 1 runs fine on your laptop. In production it runs in a container that the platform stops on every deploy, every scale-down and every node drain. Things go wrong in ordinary ways: - CMD python app.py in shell form. /bin/sh becomes PID 1, and depending on the shell and image, your app may never see SIGTERM. After the grace period the runtime sends SIGKILL, and an agent halfway through a refund just stops. - ENV OPENAIAPIKEY=... in the Dockerfile. The key is now in an image layer, readable by anyone who can pull the image, forever. - FROM python:latest. A rebuild next month gets a different Python, and "roll back to last week" rolls back to an image you can't rebuild. - Missing .env in .dockerignore. COPY . . copies your local secrets into the image.
Loading the full lesson…