Chapter 10: Action Plan


This chapter distils the book into a prioritised, repeatable checklist. Apply it to any existing project — or use it as a baseline for every new one.


Phase 1: Audit Your Current Image

Before changing anything, measure what you have. You cannot improve what you have not measured.


Phase 2: High-Impact Changes (Do These First)

These four changes deliver the most size reduction for the least effort. Apply them in this order.

2.1 Switch the base image

Replace the full base image with a slim or alpine variant.

2.2 Add a .dockerignore file

2.3 Chain all RUN instructions

2.4 Add a multi-stage build


Phase 3: Medium-Impact Changes

3.1 Package manager hygiene

3.2 COPY ordering

3.3 Security hygiene


Phase 4: CI/CD Automation


Phase 5: Language-Specific Tuning

Apply after the baseline optimisations are in place.

Python:

Node.js:

Go:

Java:


Size Targets Reference

Use these as benchmarks. If your image is larger, there is recoverable size.

Runtime Realistic target
Go (scratch) 10–25 MB
Python (slim + venv) 70–120 MB
Node.js (alpine + prod deps) 80–180 MB
Java (JRE-alpine) 180–250 MB
Java (jlink custom JRE) 80–150 MB

Quick Reference: Optimisation Priority

Priority Technique Expected reduction
1 Switch to slim/alpine base image 50–80%
2 Add multi-stage build 40–70%
3 Chain RUN instructions 5–30%
4 Add .dockerignore Build speed, minor size
5 Package manager flags 5–20%
6 BuildKit cache mounts Build speed only
7 Language-specific tuning 10–30%

Resources


Closing Thought

A 500 MB image reduced to 80 MB is not just 420 MB saved on one server. It is 420 MB saved on every pull, on every node, on every deploy, across the entire lifetime of the service. On a fleet of twenty microservices deploying ten times a day to ten nodes, that is 84 GB of data transfer eliminated every day — before accounting for faster cold starts, a smaller CVE surface, and the compound interest of keeping these habits as the fleet grows.

The techniques in this book require a day of work to apply to an existing project and twenty minutes to apply to a new one. The return is indefinite.


← Chapter 9: CI/CD Integration Table of Contents