Building lean Docker images

Dec 3, 2018 · 3 min read
Image for post
Image for post
Photo by SpaceX on Unsplash

Separating build and runtime dependencies

No matter which language you use — whether it’s Node.js, Go, Python, or something else — it’s almost inevitable that you’ll have both build and runtime dependencies.

Consolidating shared dependencies into a base image

If you have more than a few applications sharing the same stack and some of the same dependencies, you can create a base image to reduce total build time. This means that rather than re-installing shared dependencies for every build you can pull the layers in binary form, no compilation/installation required!

docker build --file parent.Dockerfile --tag parent .

Build stages and scratch-based images

This example pertains more to compiled applications. In these cases you can compile your application using one Docker image, and then copy the binary into a scratch image as a single binary. scratch images have no base layers, so they’re super lightweight!

Localz Engineering

We build cool and awesome stuff for the Individual Economy

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store