What you'll learn
- Run, inspect and debug containers with the docker CLI
- Write efficient, secure multi-stage Dockerfiles
- Persist data and connect containers safely
- Describe a multi-service application with Compose
- Build, scan, sign and push images in CI
Each lesson is tagged Junior, Mid or Expert, so you can start where you are. Finish with the lab and the quiz; a score of 4 out of 5 marks the course complete in this browser.
The lessons below are in English for now, because they quote technical names, commands and log fields. An Arabic version is planned.
Course map
Each module moves from fundamentals to applied work to an expert challenge. Exercises have worked solutions: try first, then open the solution. 10 modules · 21 exercises · ~4 hours
- 0Start here: Docker's architecture and the docker commandJuniorMidExpert20 min · 1 exercises
- 1Running and managing containersJuniorMidExpert25 min · 3 exercises
- 2Images: pull, tag, inspect and choose a baseJuniorMidExpert20 min · 2 exercises
- 3Writing a DockerfileJuniorMidExpert30 min · 2 exercises
- 4Production-grade imagesJuniorMidExpert25 min · 3 exercises
- 5Storing data: volumes, bind mounts and tmpfsJuniorMidExpert20 min · 2 exercises
- 6Networking containersJuniorMidExpert20 min · 2 exercises
- 7Docker Compose: multi-container applicationsJuniorMidExpert30 min · 3 exercises
- 8Shipping and securing imagesJuniorMidExpert30 min · 2 exercises
- 9Troubleshooting, cheat sheet and assessmentJuniorMidExpert20 min · 1 exercises
No prior experience is needed. Module 0 covers the architecture, installation and configuration, and sets up the project you extend in every module. Each command is labelled with its impact (read-only, changes files, changes the system, uses the network). Work on a computer or virtual machine you control.
Start here: Docker's architecture and the docker command
Goal: Know what each Docker component does, install it safely, and read any docker command.
What Docker is made of
Docker is a platform for building, sharing and running containers. The docker CLI sends requests to the Docker Engine (dockerd), which uses containerd to manage images and runc to start containers (see the Containers course). BuildKit builds images; Compose runs multi-container applications.
Docker turned containers into a one-command experience and defined the developer workflow most teams still use: a Dockerfile in the repository, an image in a registry, the same image in every environment.
Quick check: Which component actually creates the container's namespaces and cgroups?
dockerd and containerd prepare everything; runc makes the kernel calls.
Install and check Docker
Install Docker Desktop with the WSL 2 back end (it runs the engine in a small Linux VM). Large companies need a paid Docker subscription for Desktop.
Install Docker Desktop, or a free alternative such as colima or OrbStack, which provide the same docker CLI.
curl -fsSL https://get.docker.com -o get-docker.sh # read it before running
sudo sh get-docker.sh
dockerd-rootless-setuptool.sh install # optional: rootless modeAdding your user to the docker group lets you skip sudo, but that group is equivalent to root on the host. Rootless mode is the safer option.
$ docker version --format 'client {{.Client.Version}}, server {{.Server.Version}}'
client 29.x, server 29.x
$ docker run --rm hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.Anatomy of a docker command
docker run -d --name tracker -p 127.0.0.1:8080:8080 -e PORT=8080 --restart unless-stopped ghcr.io/rimal-logistics/tracker:1.4.03f9c2b1e7d4a8c6b5e0f1a2d3c4b5a69788f7e6d5c4b3a291807f6e5d4c3b2a1
Exercise 1Junior
Name the parts of docker run --rm -it -v $PWD:/work -w /work python:3.14-slim python3 --version.
Worked solution
--rm delete the container when it exits; -it interactive with a terminal; -v $PWD:/work bind-mount the current folder; -w /work working directory; image python:3.14-slim; command python3 --version replaces the image's default CMD.
Tools in this course
The daemon and command line for images, containers, networks and volumes.
Use it for: every Docker workflow
Integrates with: containerd, BuildKit, Compose
Defines and runs multi-container apps from compose.yaml (Compose v5).
Use it for: local stacks, integration tests
Integrates with: Docker Engine, CI
Concurrent, cached, multi-platform image builder.
Use it for: fast, reproducible builds
Integrates with: registries, GitHub Actions cache
Public registry with Docker Official Images.
Use it for: base images
Integrates with: every engine
Daemonless, rootless alternative with a compatible CLI (alias docker=podman).
Use it for: servers without a daemon
Integrates with: Kubernetes YAML, systemd
The tracker project
Goal: The shipment tracker (app.py and tests) is in ~/tracker; you will containerise it, run it with a proxy and database, and ship it through CI.
mkdir -p ~/tracker && cd ~/tracker && git init -q 2>/dev/null; cd ~/tracker && ls && python3 -m unittest -q 2>&1 | tail -n 1app.py test_app.py OK
Running and managing containers
Goal: Run, inspect, debug and remove containers, and understand states, exit codes and restart policies.
Images: pull, tag, inspect and choose a base
Goal: Work with image references, digests and layers, and choose a secure, small base image.
Writing a Dockerfile
Goal: Write a Dockerfile, control the build context, use the cache well, and build the tracker image.
Production-grade images
Goal: Use multi-stage builds, run tests in the build, keep secrets out, build for several platforms, and lint Dockerfiles.
Storing data: volumes, bind mounts and tmpfs
Goal: Keep data beyond a container's life, share files with the host safely, and avoid permission problems.
Networking containers
Goal: Connect containers by name on user-defined networks, publish only what users need, and debug connectivity.
Docker Compose: multi-container applications
Goal: Describe the tracker, a reverse proxy and a database in one compose.yaml with health checks, secrets and hardening.
Shipping and securing images
Goal: Tag and push images, build them in CI with caching, scan and sign them, and run containers with least privilege.
Troubleshooting, cheat sheet and assessment
Goal: Diagnose the common Docker failures quickly, review the course, and containerise a new service.
Quick reference (the cheat-sheet lessons and the PDF content)
Commands you use every day
docker build -t shop/api:1.4.0 .
docker images --digests
docker pull python:3.13-slim
docker tag shop/api:1.4.0 registry.example.com/shop/api:1.4.0
docker push registry.example.com/shop/api:1.4.0
docker image prune -f # remove dangling layers
docker history shop/api:1.4.0 # size per layerdocker run -d --name api -p 127.0.0.1:8080:8000 \
--read-only --tmpfs /tmp --memory 512m --cpus 1 \
--env-file .env shop/api:1.4.0
docker ps -a
docker logs -f --since 10m api
docker exec -it api sh # debug shell
docker stats --no-stream
docker stop api && docker rm apiA Dockerfile that caches well and ships small
# syntax=docker/dockerfile:1
FROM python:3.13-slim AS build
WORKDIR /src
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
pip wheel -r requirements.txt -w /wheels
COPY . .
FROM python:3.13-slim
RUN useradd -u 10001 -r app
WORKDIR /app
COPY --from=build /wheels /wheels
RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels
COPY --from=build --chown=app /src/app ./app
USER 10001
EXPOSE 8000
HEALTHCHECK CMD python -c "import urllib.request,sys; \
urllib.request.urlopen('http://127.0.0.1:8000/health')"
ENTRYPOINT ["python", "-m", "app"]Why each choice
- Dependencies copied before code: rebuilds reuse the cached layer
- Multi-stage: compilers stay in the build stage
- BuildKit cache mount speeds up pip
- Non-root
USERwith a fixed UID - Exec-form
ENTRYPOINT: signals reach your app HEALTHCHECKlets Compose and orchestrators restart it- Pin base images by digest in production
Dockerfile instruction cheat sheet
| Instruction | Use it for | Gotcha |
|---|---|---|
FROM | Base image; name stages with AS | :latest breaks reproducible builds |
RUN | Install packages, build | Chain and clean in the same layer: apt-get update && apt-get install -y … && rm -rf /var/lib/apt/lists/* |
COPY vs ADD | COPY local files | ADD also fetches URLs and unpacks archives: prefer COPY |
ARG vs ENV | Build-time vs runtime variables | Both end up in image metadata: never secrets |
RUN --mount=type=secret | Use a token during build only | Not stored in any layer |
ENTRYPOINT + CMD | Fixed program + default arguments | Shell form wraps in sh -c and swallows SIGTERM |
.dockerignore | Exclude .git, .env, node_modules | Missing it leaks secrets and slows builds |
Choosing a base image
| Base | Size (approx.) | Pros | Cons |
|---|---|---|---|
| Full distro (debian, ubuntu) | 75–120 MB | Everything works, easy debugging | More packages, more CVEs |
-slim variants | 25–50 MB | Good default, glibc | Some tools missing |
| Alpine | 5–8 MB | Tiny | musl libc can break Python wheels and DNS edge cases |
| Distroless / hardened minimal | 2–20 MB | No shell or package manager: small attack surface | Debug with docker debug or an ephemeral container |
scratch | 0 MB | Static Go or Rust binaries | You add CA certificates and time zones yourself |
Compose: a multi-service app
compose.yaml essentials
services:
api:
build: ./api
env_file: .env
secrets: [db_password]
depends_on:
db: { condition: service_healthy }
networks: [front, back]
restart: unless-stopped
db:
image: postgres:17
volumes: [db-data:/var/lib/postgresql/data]
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
networks: [back]
volumes: { db-data: {} }
networks: { front: {}, back: { internal: true } }
secrets:
db_password: { file: ./secrets/db_password }Compose commands
docker compose up -d --build
docker compose ps
docker compose logs -f api
docker compose exec db psql -U postgres
docker compose config # final merged file
docker compose down # keep volumes
docker compose down -v # also delete volumes!
docker compose watch # sync code while developingDebugging: symptom to first move
| Symptom | First move |
|---|---|
| Exits immediately | docker logs api; docker inspect api --format '{{.State.ExitCode}}' |
| Exit code 137 | Out of memory: docker inspect --format '{{.State.OOMKilled}}'; raise the limit or fix the leak |
| Works locally, not in container | Listening on 127.0.0.1 inside? Bind to 0.0.0.0 in the container |
| Cannot reach another container | Same user-defined network? Use the service name, not localhost |
| Slow builds | Order layers by change frequency; add .dockerignore; use cache mounts |
| Image too big | docker history, multi-stage build, slim base |
| No shell in a distroless image | docker debug api (Docker Desktop) or a debug container with --pid container:api |
| Disk full | docker system df; docker system prune (check first) |
Image security pipeline
Fail the build on fixable critical CVEs, rebuild weekly to pick up base-image patches, and add only the Linux capabilities the app needs.
docker group is effectively root on that machine.Key terms
- Image / container
- The packaged file system and settings / a running instance of it.
- Dockerfile
- The build recipe; each instruction adds a layer or metadata.
- Multi-stage build
- Several FROM stages; only what the final stage copies ships.
- Volume
- Docker-managed storage that outlives containers.
- Compose
- compose.yaml describing services, networks, volumes and secrets.
- Build context
- The folder sent to the builder; filtered by .dockerignore.
Hands-on lab
Knowledge check
Answer all five questions, then check your answers. Each answer comes with a short explanation.
Further reading
- Docker documentation docs.docker.com
- Dockerfile reference docs.docker.com
- Compose Specification compose-spec.io
- Docker Engine security docs.docker.com
- Hadolint github.com
- CIS Docker Benchmark cisecurity.org
Put it into practice
Use these ThreatAI tools to apply what you learned to your own environment.