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
