Skip to content

apt-get-no-recommends

Dockerfileperformanceno fixdefault: offdockerfile/hadolint

Reports an apt-get install that also installs recommended packages. --no-install-recommends (or -o APT::Install-Recommends=false) stops that. Other apt-get commands are not checked.

By default apt-get also installs the packages that a package only recommends, which it does not need to run. In an image they add size and build time, and more software to patch and to be attacked through.

With the flag only the real dependencies are installed; name anything else you need yourself.

Reported
FROM debian:12
RUN apt-get update && apt-get install curl
RUN apt-get install -y curl=7.88 wget=1.21
...
RUN apt-get install -qq -y -t stable curl=7.88
RUN apt-get -y install foo/stable
RUN apt-get install -yq ./a.deb
RUN apt-get install --yes \
curl \
git
RUN apt-get update
# a blank line or a comment before an instruction does not hide it
RUN apt-get install -y curl=7.88
dockerfile:
lint:
rules:
apt-get-no-recommends: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line apt-get-no-recommends in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
hadolint DL3015 full