I recently read this great article about docker image size, how it works, and why it matters. Up until now I hadn’t given any thought to the size of the containers I’m building.
Dive is the cli tool I’m using to inspect each layer of the final docker container.
I gave these quick changes a try, and am pretty astonished by the results:
My Fetch Image Proxy project was the most recent offender so I started there.
I was using
FROM node:17 without any build step. This meant that npm libraries, and the overhead of a debian base was weighing the container to 1 GB in space!
Switching to a build step had the biggest impact, but using
gcr.io/distroless/nodejs:16 distroless images for the runtime also made a slight difference. Both small changes combined brought the overall size to
124 MB, about an 8x reduction in disk space.
I probably should have known this so far into my career with docker, but if I did I would not have had this fun tooling experience.
This is the gcr template for nodejs: https://github.com/GoogleContainerTools/distroless/blob/main/examples/nodejs/Dockerfile