Docker mastery: custom
This course reads the production Dockerfile that rails new generates and explains its decisions. It covers layers, the build cache and multi-stage builds that leave compilers and gem caches behind. Faster builds come from .dockerignore, cache mounts, secret mounts and registry caching in CI. It then turns to smaller and safer images: slim base images, pinned versions, keeping keys out of layers, non-root users and scanning. Final lessons cover runtime behavior (ENTRYPOINT, CMD, PID 1 and signals, health checks, logs) and a custom change with a review checklist.
What you'll learn
- ✓How layers and the build cache decide what rebuilds
- ✓Multi-stage builds that ship only finished artifacts
- ✓Faster builds with .dockerignore, cache mounts and CI caching
- ✓Smaller, safer images with slim bases, non-root users and scanning
- ✓Runtime behavior: ENTRYPOINT, CMD, exec, signals and health checks
- ✓Placing a custom change and reviewing a Dockerfile with a checklist
The Dockerfile Rails gave you
rails new writes a Dockerfile. Most developers never open it, deploy with Kamal, and it works. That is a good outcome and a missed opportunity: the file is a compact lesson in production containers, and it is already in your repository.
Read the full lesson free →Curriculum
7 lessonsThe Dockerfile Rails gave you
A walk through the Dockerfile that rails new generates, its three stages and its production choices.
Layers and the build cache
How each instruction becomes a cached layer, what invalidates it, and why instruction order matters.
Multi-stage builds
Building in one stage and shipping another, so compilers, headers and gem caches never reach the image.
Making builds fast
Speeding up builds with .dockerignore, cache mounts, secret mounts and registry-backed caching in CI.
Small and safe images
Choosing a base image, keeping secrets out of layers, running as non-root and scanning for vulnerabilities.
What happens at runtime
How ENTRYPOINT and CMD work, why the entrypoint ends with exec, and how health checks and logs behave.
Putting it together: a custom Dockerfile
Adding PDF preview packages to the right stage, checking the result and reviewing with an eleven-line checklist.