PTENES
Skip to content
MODULE 5.5

🐳 Deployment and Infrastructure

Docker, Docker Compose, cloud deployment, environment management, and monitoring. From "works on my machine" to "works anywhere."

6
Topics
~50
Minutes
5.4
Prerequisite
Advanced
Type
Progress:0%0 of 6
1

📦 Docker Basics

Docker packages your app, dependencies, and configurations into a container. The Dockerfile defines how to build the image. Claude Code generates optimized Dockerfiles with multi-stage builds.

Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

In one sentence: Docker = "works on my machine" becomes "works anywhere."

2

🎼 Docker Compose

Real apps have more than one service: app + database + cache. Docker Compose orchestrates everything with a single docker-compose.yml. A docker compose up start everything together.

In one sentence: docker compose up = app + DB + cache running together in 1 command.

3

☁️ Cloud deploy (Railway/Fly.io)

Platforms like Railway and Fly.io deploy your app with one command. Connect the Git repo, configure environment variables, and every push triggers an automatic deploy. No server management.

terminal
# Railway
railway login && railway init && railway up

# Fly.io
fly launch && fly deploy

In one sentence: PaaS = deploy with one command, without managing servers.

4

🔐 Environment Management

Secrets in .env, configs by environment (dev/staging/prod), 12-factor principle. Use pydantic-settings to load and validate configurations. Never commit .env to git.

NEVER do this

Committing .env to git. Add .env to .gitignore BEFORE the first commit.

In one sentence: .env + .gitignore + pydantic-settings = secure secrets and validated configs.

5

📈 Monitoring and Logs

Minimum viable: endpoint /health, structured logging with structlog, and external uptime monitoring. Without that, you only find out about problems when a user complains.

In one sentence: /health + structlog + uptime check = know before the user does.

6

📏 Scaling Basics

Horizontal (more replicas) vs. vertical (larger machine). For 99% of early-stage projects, one replica with caching is enough. Rule of thumb: don't scale before you need to. When monitoring shows a bottleneck, then do it.

In one sentence: don't scale before you need to; when you do, monitoring shows you where.

🧾 Module Summary

✓
Docker packages the app and its dependencies in a container.
✓
Compose orchestrates multiple services.
✓
PaaS deploys without managing servers.
✓
Env management keeps secrets safe.
✓
Monitoring reveals problems before the user does.
✓
Scaling only when monitoring asks for it.

Next module:

5.6 — Ship Your Product: MVP, launch, and iteration.