Skip to main content

Optimisation for Dockers

Docker image optimisation is the practice of making images smaller, faster to build and predictable. The main tool is the multi-stage build, where one stage compiles code and a later stage copies only the finished artefact into a slim base, along with pinned versions for reproducible builds.

Stage: Building Images · Part of the Docker roadmap · Last reviewed 19 November 2026

What to learn in Optimisation

Optimisation interview questions

How does a multi-stage build reduce image size?

Each FROM starts a new stage. You compile in a stage that has compilers and dev tools, then use COPY --from to take only the built binary or bundle into a small final stage. Build tools and source never reach the shipped image.

Why does deleting a file in a later RUN not shrink the image?

Layers are additive and immutable. A file written in an earlier layer stays stored there, and a later delete only hides it in the merged view. To avoid the size, download, use and remove the file within the same RUN instruction, or use a multi-stage build.

Where Optimisation fits in the Docker roadmap

Optimisation belongs to the Building Images stage (beginner level), which takes about 12 hours. Dockerfiles.

Back to the full Docker roadmap