dnf-clean
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...RUN yum install -y curl-7.0 && yum clean allRUN yum install -y curl-7.0 && rm -rf /var/cache/yum/*RUN yum install -y nginx-1.2 && yum clean allRUN dnf install curlRUN dnf install -y curl-7.0RUN dnf install -y curl-7.0 && dnf clean allRUN microdnf install -y curl-7.0...RUN zypper install -y curl=7.0 && zypper clean...Configuration
Section titled “Configuration”dockerfile: lint: rules: dnf-clean: warn # off (default), warn, errorEnabled by the presets: dockerfile/hadolint.
Suppress one line with sudsy-disable-next-line dnf-clean in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| hadolint | DL3040 |
full |