Skip to content
docker-learning-journey logo

Docker Learning Journey

docker-learning-journey

Interactive Docker learning guide from basics to production, tailored for Python/FastAPI developers. This skill should be used when users want to learn Docker concepts, understand container fundamentals, practice Docker commands, or progress from beginner to production-ready Docker knowledge.

SKILL.md

Full skill instructions

Docker Learning Journey

An interactive, progressive Docker learning guide designed for Python and FastAPI developers. Learn by doing with practical exercises and real-world examples.

What This Skill Does

  • Teaches Docker concepts progressively (basics → intermediate → production)
  • Connects Docker concepts to Python/​FastAPI knowledge you already have
  • Provides hands-on exercises at each level
  • Offers quick command references with explanations
  • Guides containerization of FastAPI applications

What This Skill Does NOT Do

  • Cover Kubernetes (that's a separate journey)
  • Handle cloud-specific deployments (AWS ECS, GCP Cloud Run)
  • Replace official Docker documentation for edge cases

Before Starting

Assess where you are:

LevelYou Can...Start At
BeginnerHaven't used DockerModule 1
BasicRun containers, pull imagesModule 2
IntermediateWrite Dockerfiles, use composeModule 3
AdvancedMulti-stage builds, optimizationModule 4

Learning Modules

Module 1: Docker Fundamentals

Goal: Understand what Docker is and run your first container

Key Concepts:

Image      = Blueprint/​Recipe (like a Python class)
Container  = Running instance (like a Python object)
Registry   = Image storage (like PyPI for packages)

Your First Commands:

# 1. Check Docker is installed
docker --version

# 2. Pull an image (download the blueprint)
docker pull python:3.12-slim

# 3. Run a container (create an instance)
docker run -it python:3.12-slim python
# You're now inside a Python container! Type exit() to leave

# 4. See what's running
docker ps        # Running containers
docker ps -a     # All containers (including stopped)

# 5. See downloaded images
docker images

Python Analogy:

# This is like Docker:
class PythonEnvironment:        # Image
    def __init__(self):
        self.python = "3.12"
        self.packages = []

env1 = PythonEnvironment()      # Container 1
env2 = PythonEnvironment()      # Container 2 (isolated!)

Exercise: See assets/​exercises/​01-first-container.md


Module 2: Building Images with Dockerfile

Goal: Create your own images with Dockerfile

Key Concept: Dockerfile = Recipe with steps

# Every Dockerfile starts with a base image
FROM python:3.12-slim

# Set working directory (like cd)
WORKDIR /​app

# Copy files from your computer into the image
COPY requirements.txt .

# Run commands (install dependencies)
RUN pip install -r requirements.txt

# Copy your application code
COPY . .

# Default command when container starts
CMD ["python", "main.py"]

Layer Concept (Important!):

┌─────────────────────────┐
│ CMD ["python", "main.py"] │  ← Layer 5 (your command)
├─────────────────────────┤
│ COPY . .                  │  ← Layer 4 (your code)
├─────────────────────────┤
│ RUN pip install...        │  ← Layer 3 (dependencies)
├─────────────────────────┤
│ COPY requirements.txt     │  ← Layer 2 (requirements file)
├─────────────────────────┤
│ FROM python:3.12-slim     │  ← Layer 1 (base image)
└─────────────────────────┘

Each layer is CACHED! Change order matters for speed.

Build Commands:

# Build an image from Dockerfile
docker build -t myapp:v1 .

# -t = tag (name:version)
# .  = build context (current directory)

# Run your new image
docker run myapp:v1

Exercise: See assets/​exercises/​02-first-dockerfile.md


Module 3: Docker Compose (Multi-Container Apps)

Goal: Run multiple containers together (FastAPI + Database)

Key Concept: Compose = Orchestra conductor for containers

# docker-compose.yml
services:
  api:                          # Your FastAPI app
    build: .
    ports:
      - "8000:8000"             # host:container
    environment:
      - DATABASE_URL=postgresql://user:pass@db:5432/​app
    depends_on:
      - db

  db:                           # PostgreSQL database
    image: postgres:15
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
      - POSTGRES_DB=app
    volumes:
      - postgres_data:/​var/​lib/​postgresql/​data

volumes:
  postgres_data:                # Persist data between restarts

Compose Commands:

# Start all services
docker compose up

# Start in background (detached)
docker compose up -d

# Stop all services
docker compose down

# View logs
docker compose logs -f api

# Rebuild after code changes
docker compose up --build

Exercise: See assets/​exercises/​03-compose-fastapi.md


Module 4: Production Patterns

Goal: Build optimized, secure, production-ready images

Multi-Stage Builds (The Key Technique):

# Stage 1: Builder (temporary, has build tools)
FROM python:3.12-slim AS builder
COPY --from=ghcr.io/​astral-sh/​uv:latest /​uv /​bin/​uv
WORKDIR /​app
COPY pyproject.toml uv.lock ./
RUN uv sync --locked --no-dev

# Stage 2: Runtime (final, minimal)
FROM python:3.12-slim AS runtime
WORKDIR /​app
COPY --from=builder /​app/​.venv /​app/​.venv
COPY ./​app ./​app
ENV PATH="/​app/​.venv/​bin:$PATH"
CMD ["fastapi", "run", "app/​main.py", "--port", "80"]

Why Multi-Stage?

Builder Stage: 400MB (has uv, build tools)
         ↓
    Copies only .venv
         ↓
Runtime Stage: 150MB (minimal, secure)

Production Checklist:

  • Multi-stage build (small image)
  • Non-root user (security)
  • Health check (monitoring)
  • .dockerignore (exclude unnecessary files)
  • No secrets in image (use env vars)

Exercise: See assets/​exercises/​04-production-build.md


Quick Reference

Essential Commands

TaskCommand
Pull imagedocker pull image:tag
Run containerdocker run -d -p 8000:80 image
List runningdocker ps
List alldocker ps -a
Stop containerdocker stop <id>
Remove containerdocker rm <id>
List imagesdocker images
Build imagedocker build -t name:tag .
Remove imagedocker rmi image:tag
View logsdocker logs <id>
Shell intodocker exec -it <id> /​bin/​bash

Compose Commands

TaskCommand
Start servicesdocker compose up
Start detacheddocker compose up -d
Stop servicesdocker compose down
Rebuilddocker compose up --build
View logsdocker compose logs -f
Run commanddocker compose exec api bash

Port Mapping Explained

-p 8000:80
   │    │
   │    └── Container port (inside)
   └─────── Host port (your computer)

Access at: http://localhost:8000

Common Errors & Solutions

ErrorCauseSolution
"port already in use"Another process on that portChange host port or stop other process
"image not found"Typo or not pulleddocker pull image:tag
"permission denied"Docker daemon not runningStart Docker Desktop
"no space left"Docker cache fulldocker system prune
"connection refused"Container not readyAdd health check, use depends_on

Python Developer's Mental Model

PythonDocker
pip installdocker pull
requirements.txtDockerfile's RUN pip install
venvContainer isolation
python main.pydocker run
pip freezedocker images
Multiple projectsMultiple containers
.gitignore.dockerignore

Learning Path Checklist

Week 1: Foundations

  • Install Docker Desktop
  • Run hello-world container
  • Pull and run Python image
  • Understand images vs containers
  • Complete Exercise 01

Week 2: Building

  • Write first Dockerfile
  • Build custom image
  • Understand layers and caching
  • Complete Exercise 02

Week 3: Composing

  • Write docker-compose.yml
  • Run FastAPI + PostgreSQL
  • Understand volumes and networks
  • Complete Exercise 03

Week 4: Production

  • Multi-stage Dockerfile
  • Optimize image size
  • Add security practices
  • Complete Exercise 04

Reference Files

FileWhen to Read
references/​01-core-concepts.mdDeep dive into Docker architecture
references/​02-dockerfile-reference.mdAll Dockerfile instructions
references/​03-compose-reference.mdDocker Compose file format
references/​04-fastapi-docker.mdFastAPI-specific patterns
references/​05-troubleshooting.mdCommon issues and fixes

Exercises

ExerciseLevelGoal
assets/​exercises/​01-first-container.mdBeginnerRun Python in container
assets/​exercises/​02-first-dockerfile.mdBeginnerBuild custom image
assets/​exercises/​03-compose-fastapi.mdIntermediateFull stack app
assets/​exercises/​04-production-build.mdAdvancedOptimized deployment

Cheatsheets

FileContents
assets/​cheatsheets/​commands.mdAll Docker commands
assets/​cheatsheets/​dockerfile.mdDockerfile syntax
assets/​cheatsheets/​compose.mdCompose file syntax

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View