medium · dockerfile/apt-update-without-install

apt-get update separated from install

Running apt-get update in a separate layer from install leaves a stale package index.

Why it breaks the cache

A cached update layer goes stale, and unneeded recommended packages inflate the image.

Bad Dockerfile

RUN apt-get update
RUN apt-get install -y curl

Good Dockerfile

RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*

CLI

layerlint rules explain apt-update-without-install

All docs · Download