Skip to content

dnf-clean

Dockerfileperformanceno fixdefault: offdockerfile/hadolint

Reports a RUN that installs with dnf and does not clean the cache. It runs dnf install, upgrade or reinstall (also microdnf, and the short forms in, up, rei) and has no dnf clean all or microdnf clean all after it in the same RUN. An rm -rf /var/cache/libdnf5* written exactly so is accepted as well.

dnf stores the metadata and packages it downloaded under /var/cache. That cache is written into the layer and stays in the image, adding size that nothing uses at run time.

Clean it in the same RUN: a later RUN cannot shrink a layer that was already written.

Reported
...
RUN yum install -y curl-7.0 && yum clean all
RUN yum install -y curl-7.0 && rm -rf /var/cache/yum/*
RUN yum install -y nginx-1.2 && yum clean all
RUN dnf install curl
RUN dnf install -y curl-7.0
RUN dnf install -y curl-7.0 && dnf clean all
RUN microdnf install -y curl-7.0
...
RUN zypper install -y curl=7.0 && zypper clean
...
dockerfile:
lint:
rules:
dnf-clean: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line dnf-clean 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 DL3040 full