For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/dockerfile-apt-get-install-lists-were-not-deleted.md.
A documentation index is available at /llms.txt.
Leaving apt package lists in a built image after running apt-get install can expose package metadata and increase image size. This makes images larger to distribute and can retain information that aids attackers or troubleshooting of past package states.
This rule scans Dockerfile RUN instructions that invoke apt-get install and requires that the same RUN command perform cleanup by running apt-get clean and/or removing /var/lib/apt/lists/* (for example, rm -rf /var/lib/apt/lists/*). Ensure the cleanup step appears after the install in the same RUN (using && or ;) so the cache is not preserved in an earlier layer.