liveBook · Manning

Package list cache

As explained in Learn Docker in a Month of Lunches, Second Edition

A package list cache is locally stored package metadata maintained by a package manager for resolving and installing software.

A package list cache is local metadata that APT uses to resolve software packages. In a Docker image, it can consume space after installation, so remove it when package installation finishes. section 17.3

Minimize the cache during an optimized installation:

  • Combine repository update and package installation in one RUN instruction. section 17.3
  • Install only required packages with --no-install-recommends. section 17.3
  • Delete /var/lib/apt/lists/* before the instruction ends. section 17.3
  • Keep cleanup in the same RUN instruction; deleting files in a later image layer does not recover the earlier layer's space. section 17.3

Optimized APT installation

FROM debian:12-slim RUN apt-get update \ && apt-get install -y --no-install-recommends \ curl=7.88.1-10+deb12u8 \ socat=1.7.4.4-2 \ && rm -rf /var/lib/apt/lists/* section 17.3

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains the cleanup command and why later-layer deletion fails to recover space, but does not detail APT internals.
Examples
Uses Debian Slim, curl, socat, apt-get, and /var/lib/apt/lists/* in comparable Dockerfiles.
What it assumes
Assumes familiarity with Dockerfiles and basic apt-get commands.
What you can do after
Operate/configure Docker builds that install packages while minimizing retained filesystem data.
How it connects
Connects package installation with APT, Docker image layers, and container image optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.