Oversized Images

Why a Single-Stage Node.js Image Is Too Large

In a single stage, everything the build needed stays in the image: package manager, compilers, caches and tests. node:24-slim has no compilers, but a native add-on needs the full node:24 with python3, make and g++:

Measuring what a single-stage image carriesShell
sed 's/^FROM node:24-slim/FROM node:24/' Dockerfile > ../full.Dockerfile
docker build -q -f ../full.Dockerfile -t l3-booknest-api:full . >/dev/null
docker image ls l3-booknest-api
docker run --rm l3-booknest-api:full du -sh /usr/lib/gcc /usr/local/lib/node_modules/npm
Output
IMAGE                  ID             DISK USAGE   CONTENT SIZE   EXTRA
l3-booknest-api:1.0    5195d360d65d        339MB         82.1MB
l3-booknest-api:full   ac2ae4441300       1.64GB          411MB
120M    /usr/lib/gcc
19M     /usr/local/lib/node_modules/npm

The same 5 MB of code and dependencies now ships inside 1.64 GB, with 120 MB of GCC and 19 MB of npm 2,036 that production never runs, yet every node pulls and every scanner (Container Security) inspects.