For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/dockerfile-yum-clean-all-missing.md.
A documentation index is available at /llms.txt.
Dockerfile RUN instructions that perform a yum install must run yum clean all afterward to remove package manager caches and reduce image size. This prevents unnecessarily large images and the retention of cached packages or metadata that can increase attack surface.
This rule checks Dockerfile RUN commands containing yum ... install and requires that yum clean all appears later in the same RUN instruction. RUN lines with yum install but no subsequent yum clean all (or with yum clean all positioned before the install) will be flagged. If you perform multiple installs, ensure a single yum clean all follows them in the same RUN, or explicitly remove /var/cache/yum as part of the same command to guarantee caches are deleted.
Secure example:
RUN yum -y install package1 package2 && yum clean all && rm -rf /var/cache/yum