Skip to main content
Albero Academy

Docker

Package your app and its environment into a portable container.

Production10 min

Docker solves "works on my machine" by bundling your app together with its exact environment — Python version, system libraries, dependencies — into an image. That image runs identically on your laptop, in CI, and in production.

The Dockerfile

A Dockerfile is the recipe to build the image: pick a base, install dependencies, copy your code, set the run command:

Dockerfile
FROM python:3.12-slim # small official Python base
WORKDIR /app
COPY requirements.txt . # copy deps first…
RUN pip install --no-cache-dir -r requirements.txt # …so this layer caches
COPY . . # then the code
CMD ["python", "main.py"] # what to run
# build: docker build -t myapp .
# run: docker run myapp

Layers & caching

Key takeaways

  1. 01Docker packages app + its exact environment into a portable image.
  2. 02A Dockerfile is the recipe: base image, dependencies, code, run command.
  3. 03The same image runs identically in dev, CI and production.
  4. 04Order instructions so dependency layers cache — deps before code.
  5. 05Use slim base images and a .dockerignore to stay lean.

Finished this chapter?

Mark it complete to track your progress through Python.