For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/dockerfile-missing-dnf-clean-all.md.
A documentation index is available at /llms.txt.
When Dockerfile RUN commands install packages with DNF and do not remove package caches, the resulting image retains package metadata and cached packages which increase image size and can broaden the attack surface or complicate vulnerability management.
This rule checks Dockerfile RUN instructions: any RUN that contains a dnf install command (including variants such as dnf in, dnf reinstall, dnf rei, dnf install-n, dnf install-na, dnf install-nevra) must be followed by a dnf clean all invocation. The dnf clean all may appear in the same RUN (recommended, chained with &&) or in a subsequent RUN later in the Dockerfile. RUN commands that perform a dnf install but have no later RUN containing dnf clean will be flagged.