apt-get install --no-install-recommends
Updated 2026-07-16: expanded into a full example with the apt-config default.
I reach for --no-install-recommends in a lot of Dockerfiles now. Debian and Ubuntu packages have hard dependencies plus a set of “recommended” packages, and apt-get install pulls in the recommends by default. That is fine on a desktop, but it is bloat you rarely want in an image.
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
Ubuntu measured a 60% image size reduction from this flag on their own images.
To make it the default for every install in an image instead of repeating the flag, set it in an apt config:
RUN echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/99norecommends
The one gotcha: once in a while a recommended package is actually one you need, and something breaks in a non-obvious way without it. When that happens, install it explicitly by name alongside the rest rather than dropping the flag.