Sign in Start free

EngineeringFree course

Docker: Build, Ship and Run

The complete Docker workflow on a real service: the engine and CLI, containers, images, Dockerfiles and multi-stage builds, volumes, networks, Compose stacks, registries and CI, image and runtime security, and troubleshooting.

  • Level Junior → Expert
  • Time 240 min
  • Modules 10
  • Exercises 21 with worked solutions
  • Includes Lab, 5-question quiz, references

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

  1. 0Start here: Docker's architecture and the docker commandJuniorMidExpert20 min · 1 exercises
  2. 1Running and managing containersJuniorMidExpert25 min · 3 exercises
  3. 2Images: pull, tag, inspect and choose a baseJuniorMidExpert20 min · 2 exercises
  4. 3Writing a DockerfileJuniorMidExpert30 min · 2 exercises
  5. 4Production-grade imagesJuniorMidExpert25 min · 3 exercises
  6. 5Storing data: volumes, bind mounts and tmpfsJuniorMidExpert20 min · 2 exercises
  7. 6Networking containersJuniorMidExpert20 min · 2 exercises
  8. 7Docker Compose: multi-container applicationsJuniorMidExpert30 min · 3 exercises
  9. 8Shipping and securing imagesJuniorMidExpert30 min · 2 exercises
  10. 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.

0

Start here: Docker's architecture and the docker command

Goal: Know what each Docker component does, install it safely, and read any docker command.

20 min

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.

docker CLIdocker build / run / composeDockerREST APIunix:///var/run/docker.sockdockerdimages, networks, volumesDockercontainerdimage store, snapshotscontainerdruncnamespaces + cgroupsBuildKitbuilds imagesBuildKitRegistrypull / pushDocker HubThe socket is root-equivalent:whoever can talk to it controls the host.
WriteVS CodeVS CodeGitGitBuildBuildKitBuildKitHadolintHadolintRunDockerDockerDocker ComposeDocker ComposePodmanPodmanStoreDocker HubDocker HubGHCRGHCRHarborHarborAutomateGitHub ActionsGitHub ActionsGitLab CIGitLab CISecureTrivyTrivySyftSyftSigstoreSigstoreOperatePortainerPortainerKubernetesKubernetesThe Docker workflow and the tools you meet in this course.
Developer laptopDocker Desktop / EngineDockerNEWDockerfileBuildKitImageRegistryUsersproxytrackerdbCI pipelinenetwork (private)secretvolume: dbdataScannersStage 0: a developer laptop with Docker.

Quick check: Which component actually creates the container's namespaces and cgroups?

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.

Example output
$ 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

1
Command group and verb: run = create + start.
2
-d: detached; --name: a stable name instead of a random one.
3
Publish a port: host 127.0.0.1:8080 → container 8080.
shell · docker run, part by part
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.0
4
Environment variable for the app.
5
Restart policy: come back after a crash or reboot.
6
Image reference: registry/namespace/repository:tag.
Example output (the new container's ID)
3f9c2b1e7d4a8c6b5e0f1a2d3c4b5a69788f7e6d5c4b3a291807f6e5d4c3b2a1

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

Docker Engine and CLIBuild

The daemon and command line for images, containers, networks and volumes.

Use it for: every Docker workflow

Integrates with: containerd, BuildKit, Compose

Docker ComposeBuild

Defines and runs multi-container apps from compose.yaml (Compose v5).

Use it for: local stacks, integration tests

Integrates with: Docker Engine, CI

BuildKit / buildxBuild

Concurrent, cached, multi-platform image builder.

Use it for: fast, reproducible builds

Integrates with: registries, GitHub Actions cache

Docker HubArtifacts

Public registry with Docker Official Images.

Use it for: base images

Integrates with: every engine

PodmanBuild

Daemonless, rootless alternative with a compatible CLI (alias docker=podman).

Use it for: servers without a daemon

Integrates with: Kubernetes YAML, systemd

Project step 0

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.

shell
mkdir -p ~/tracker && cd ~/tracker && git init -q 2>/dev/null; cd ~/tracker && ls && python3 -m unittest -q 2>&1 | tail -n 1
Output
app.py
test_app.py
OK
1

Running and managing containers

Goal: Run, inspect, debug and remove containers, and understand states, exit codes and restart policies.

25 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

2

Images: pull, tag, inspect and choose a base

Goal: Work with image references, digests and layers, and choose a secure, small base image.

20 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

3

Writing a Dockerfile

Goal: Write a Dockerfile, control the build context, use the cache well, and build the tracker image.

30 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

4

Production-grade images

Goal: Use multi-stage builds, run tests in the build, keep secrets out, build for several platforms, and lint Dockerfiles.

25 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

5

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.

20 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

6

Networking containers

Goal: Connect containers by name on user-defined networks, publish only what users need, and debug connectivity.

20 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

7

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.

30 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

8

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.

30 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

9

Troubleshooting, cheat sheet and assessment

Goal: Diagnose the common Docker failures quickly, review the course, and containerise a new service.

20 min

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

Quick reference (the cheat-sheet lessons and the PDF content)
1

Commands you use every day

Junior
shell · images
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 layer
shell · containers
docker 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 api
2

A Dockerfile that caches well and ships small

Mid
Dockerfile · multi-stage Python
# 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 USER with a fixed UID
  • Exec-form ENTRYPOINT: signals reach your app
  • HEALTHCHECK lets Compose and orchestrators restart it
  • Pin base images by digest in production
3

Dockerfile instruction cheat sheet

JuniorMid
InstructionUse it forGotcha
FROMBase image; name stages with AS:latest breaks reproducible builds
RUNInstall packages, buildChain and clean in the same layer: apt-get update && apt-get install -y … && rm -rf /var/lib/apt/lists/*
COPY vs ADDCOPY local filesADD also fetches URLs and unpacks archives: prefer COPY
ARG vs ENVBuild-time vs runtime variablesBoth end up in image metadata: never secrets
RUN --mount=type=secretUse a token during build onlyNot stored in any layer
ENTRYPOINT + CMDFixed program + default argumentsShell form wraps in sh -c and swallows SIGTERM
.dockerignoreExclude .git, .env, node_modulesMissing it leaks secrets and slows builds
4

Choosing a base image

Mid
BaseSize (approx.)ProsCons
Full distro (debian, ubuntu)75–120 MBEverything works, easy debuggingMore packages, more CVEs
-slim variants25–50 MBGood default, glibcSome tools missing
Alpine5–8 MBTinymusl libc can break Python wheels and DNS edge cases
Distroless / hardened minimal2–20 MBNo shell or package manager: small attack surfaceDebug with docker debug or an ephemeral container
scratch0 MBStatic Go or Rust binariesYou add CA certificates and time zones yourself
5

Compose: a multi-service app

JuniorMid
compose.yaml · project "shop"proxynginx · ports 443:443network: frontapibuild: ./apinetworks: front, backdbpostgres:17network: backvolume db-datasecretdb_passwordfile, not envhealthcheckdepends_on: conditionHTTP5432Only the proxy publishes a port.db is reachable only on the back network.
6

compose.yaml essentials

Mid
yaml
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 }
7

Compose commands

Junior
shell
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 developing
8

Debugging: symptom to first move

JuniorMid
SymptomFirst move
Exits immediatelydocker logs api; docker inspect api --format '{{.State.ExitCode}}'
Exit code 137Out of memory: docker inspect --format '{{.State.OOMKilled}}'; raise the limit or fix the leak
Works locally, not in containerListening on 127.0.0.1 inside? Bind to 0.0.0.0 in the container
Cannot reach another containerSame user-defined network? Use the service name, not localhost
Slow buildsOrder layers by change frequency; add .dockerignore; use cache mounts
Image too bigdocker history, multi-stage build, slim base
No shell in a distroless imagedocker debug api (Docker Desktop) or a debug container with --pid container:api
Disk fulldocker system df; docker system prune (check first)
9

Image security pipeline

MidExpert

Fail the build on fixable critical CVEs, rebuild weekly to pick up base-image patches, and add only the Linux capabilities the app needs.

LinthadolintBuildBuildKit, SBOMScanTrivy / Grype / ScoutSigncosignPushprivate registryRunnon-root, read-only
Rootless Run the Docker daemon in rootless mode on shared build hosts. Anyone in the 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

Premium This part is included in the Premium and Pro plans. Sign in or see the plans to continue.

Knowledge check

Answer all five questions, then check your answers. Each answer comes with a short explanation.

1What does docker stop do first?
2Why copy dependency files before the source code?
3Where should a database password come from?
4Containers on a user-defined network can…
5Mounting /var/run/docker.sock into a container gives it…

Further reading

Put it into practice

Use these ThreatAI tools to apply what you learned to your own environment.