Skip to content
Goal: Proficient✓ Sources verified 2026-11-24DockerComposeGitHub ActionsHealth Checks

Docker, CI/CD and Deployment ​

In a small team, deployment and monitoring are the developer's job too: you own the outcome in production.

Core concepts ​

ConceptDescription
Multi-stage buildsOne stage installs dependencies / compiles, and the final image copies only what's needed at runtime, making it smaller and safer
Docker ComposeDefines several services (web, api, worker, postgres, redis) in one YAML file
Health checksContainer HEALTHCHECK / the orchestrator's liveness and readiness probes
CI/CDAutomatically test, build images and deploy after each commit (e.g. GitHub Actions)
Next.js standaloneoutput: 'standalone' bundles only the files needed at runtime, well suited to Docker

How it works ​

  • Layer caching: each Dockerfile instruction is a layer, and unchanged earlier layers are reused from cache. So copy the dependency manifest and install dependencies first, then copy the source.
  • Process model: one main process per container; the API and the worker use the same image with different start commands.
  • Configuration: injected through environment variables (12-Factor); never bake secrets into the image.

In practice ​

FastAPI image (dependencies managed with uv) ​

dockerfile
FROM python:3.13-slim AS base
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev            # dependency layer: source changes don't invalidate it
COPY . .
ENV PATH="/app/.venv/bin:$PATH"
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

docker-compose.yml (excerpt) ​

yaml
services:
  api:
    build: ./backend
    env_file: .env
    depends_on:
      db: { condition: service_healthy }
  worker:
    build: ./backend
    command: python -m app.worker
    env_file: .env
  web:
    build: ./frontend
    ports: ["3000:3000"]
  db:
    image: pgvector/pgvector:pg17
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
  redis:
    image: redis:7

Go-live checklist ​

  • Health check endpoints /healthz (liveness) and /readyz (dependencies ready)
  • Database migrations (Alembic) run as a separate step in the deploy pipeline
  • Logs to stdout as structured JSON with a trace_id
  • Alerts: error rate, P95 latency, LLM call failure rate, task backlog, human queue length
  • Rollback plan: version-tag images so you can return to the previous release in one step

Common pitfalls ​

  1. COPYing .env or secrets into the image: exclude them with .dockerignore.
  2. depends_on only waits for the container to start, not for the service to be ready: pair it with condition: service_healthy.
  3. Graceful worker shutdown: on SIGTERM, finish or release the current task, or it stays stuck in running.
  4. Tagging images only as latest: no way to roll back or trace.

Common interview questions ​

  1. What are the benefits of multi-stage builds? How do you write a Dockerfile to make the most of the cache?
  2. How is your project deployed? How do you roll back when something goes wrong?
  3. What's the difference between liveness and readiness probes?
  4. When a container is stopped, what happens to the task it's running?
  5. Which monitoring alerts would you set up for an LLM application?

To be verified / may go stale

  • The image versions in the examples (python:3.13-slim, pgvector/pgvector:pg17, redis:7) are only illustrative. Choose based on the current stable versions and license requirements.

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section