Skip to content
Hands-on IT IT Drills

Foreword

Read a little, type a lot. This book starts with a bad Dockerfile: one stage, the whole project via COPY . ., an image over a gigabyte in size, the process runs as root, and the API key sits as an ENV right in the middle of the image. Day by day you turn it into an image that contains only what is necessary, builds fast, runs as a normal user and no longer gives away any secret. Everything runs on your laptop: Docker with BuildKit, a local registry and a small demo application notes made of a Go API, a Python worker and a Node frontend.

The second focus is secrets. An API key belongs neither in the Git repository nor in an image layer, and yet the build and the container need it. You see for yourself how a key ends up in the image via ARG, ENV, COPY or a forgotten rm, and how to find it there again. Then you build it the right way: .env only locally, .gitignore and .dockerignore as a protective layer, build secrets via RUN --mount=type=secret and runtime secrets as files instead of environment variables.

The book is aimed at platform engineers, developers, and DevOps and security people who want not only to get Dockerfiles running, but to understand them, review them and enforce them in their team.

Checks are done with five tools that complement each other: hadolint and BuildKit’s build checks read the Dockerfile, ShellCheck the scripts, trivy looks for misconfigurations, secrets and known vulnerabilities, and dockle checks the finished image. You can find the companion code on GitHub at https://github.com/thomaszachmann/dockerfiles-zum-anfassen.

The training rules

  1. Type, don’t copy. Every command once by yourself.
  2. Compare with Expected. After every drill you find what you should see. If it differs, that is where the real lesson is.
  3. Pass the checkpoint. Only when every check command shows what is expected do you move on.
  4. Solve the challenge on your own. First the hint, then the solution.
  5. Lab values stay in the lab. lab-api-key-123, lab-artifact-token-123 and all other lab-… values are practice data. A real key never belongs in a file you create in this book.

Warning: Base images get new versions and security updates all the time. Image sizes, digests, build times and the number of CVEs found will differ on your machine. What matters is the ratio: before versus after.

Structure of each training day

Section Purpose
Briefing The essentials in a few bullet points
Drills Commands with expected output
Checkpoint Check script: did everything work?
Challenge A task without instructions
Enterprise Note What is different in production

The training plan

Part Day Unit
Training ground 0 Docker, buildx, local registry, demo application, cleanup
A – Fundamentals 1 The first Dockerfile: images, containers, layers
2 Instructions in detail: ENTRYPOINT, PID 1, ARG, ENV, HEALTHCHECK
3 Build context and .dockerignore
4 Mastering the layer cache
B – Multi-stage 5 Multi-stage basics: Go to scratch
6 Multi-stage for Python and Node
7 Advanced patterns and multi-platform
8 Choosing base images
C – Best practices 9 Hardening: non-root, read-only, build checks
10 Traceable and verified: labels, SBOM, Trivy
D – Secrets 11 How secrets leak
12 .env, .gitignore and .dockerignore
13 Build secrets with BuildKit
14 Runtime secrets
Competition 15 Disaster drills
Appendix A Cheat Sheet
B Final Exam

Part A shows what really happens when an image is built. Part B makes the image small. Part C makes it secure and verifiable. Part D makes sure no secret ends up in the repository, in the image or in the build log. Day 15 trains for the real emergency.

Tip: The tested versions of Docker, buildx, Compose and all base images are listed on Day 0. If an option behaves differently for you: the Dockerfile reference at docs.docker.com/reference/dockerfile/ and docker build --check.

Let’s go.

Thomas Zachmann, 2026