Home / Your Stack / Docker & Containers
Lesson 4 of 4

Docker & Containers

Concept

A container is a lightweight, isolated box that runs your app with all its dependencies. A Dockerfile is the recipe — what to install, what to copy, how to start. docker-compose.yml orchestrates multiple containers together.
m3shdup/Dockerfile
FROM python:3.12.9-slim          # Start from a Python base image
WORKDIR /app                      # Set the working directory
COPY requirements.txt .            # Copy deps list
RUN pip install -r requirements.txt # Install deps
COPY . .                           # Copy your code
CMD ["python", "run.sh"]         # Start command

What's happening

Each line is a layer. FROM picks the starting image. COPY puts your files in. RUN executes commands during build. CMD is what runs when the container starts. Docker caches unchanged layers — that's why requirements.txt is copied separately (deps don't change often, so that layer is cached).

Quick Check — 3 questions

1. What does docker compose up -d --build do?

2. Why is COPY requirements.txt . before COPY . .?

3. How do you view a running container's recent output?