delete-apt-lists
What it does
Section titled “What it does”Reports a RUN that updates the apt package lists and does not delete them. It runs apt-get update or apt update and has no rm of /var/lib/apt/lists after it in the same RUN. apt-get clean does not count, it empties another directory. A RUN with a --mount of type cache or tmpfs on /var/lib/apt/lists is not reported.
Why it matters
Section titled “Why it matters”apt-get update downloads the package index files into /var/lib/apt/lists, often tens of megabytes that no program needs at run time. They are written into the layer of that RUN, and deleting them in a later RUN hides them but does not make the image smaller, because the earlier layer still holds the files.
To fix, remove them in the same RUN: apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/*.
Example
Section titled “Example”...RUN a | bFROM debian:12...RUN apt-get updateRUN apt-get update && apt-get install -y aRUN apt updateRUN apt-get update && rm -rf /var/lib/apt/lists/*RUN apt-get update && apt-get install -y a && rm -fr "/var/lib/apt/lists"RUN --mount=type=cache,target=/var/lib/apt/lists apt-get update...Configuration
Section titled “Configuration”dockerfile: lint: rules: delete-apt-lists: warn # off (default), warn, errorEnabled by the presets: dockerfile/hadolint.
Suppress one line with sudsy-disable-next-line delete-apt-lists in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| hadolint | DL3009 |
partial | Only the RUN that runs apt-get update is checked, and any rm of a path under /var/lib/apt/lists in it counts, as hadolint does. |