Phase 1 — Foundations · Lesson 15 · 20 XP
Docker
A container packages your app with everything it needs to run — sharing the host machine's kernel, unlike a full virtual machine, which makes it lightweight and fast to start. A Dockerfile describes how to build the image: FROM a base image, COPY your code in, RUN setup commands, CMD the thing that starts the app.
FROM python:3.13-slim
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN pip install uv && uv sync --frozen
COPY . .
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0"]Copying pyproject.toml and uv.lock before the rest of the source (rather than COPY . . first) means Docker can reuse the cached dependency-install layer whenever only your application code changes, not your dependencies — a much faster rebuild loop. docker compose runs multiple containers together, e.g. your API plus a Postgres container, with one command.
Exercise
Write a Dockerfile for your Lesson 14 API, and a docker-compose.yml that runs it alongside a Postgres container with a persisted volume. Build and run the whole stack locally with one command.
Check yourself
1. What's the difference between a Docker image and a Docker container?
2. Why copy pyproject.toml and uv.lock before the rest of the source code in a Dockerfile?
Project: CRUD API with Postgres
Answer the check-yourself questions to unlock this