Skip to content
varnav edited this page Apr 27, 2019 · 3 revisions

Delete the apt-get lists after installing something.

Problematic code:

RUN apt-get update && apt-get install -y python

Correct code:

RUN apt-get update && apt-get install -y python \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

Rationale:

https://docs.docker.com/engine/articles/dockerfile_best-practices/

In addition, cleaning up the apt cache and removing /var/lib/apt/lists helps keep the image size down. Since the RUN statement starts with apt-get update, the package cache will always be refreshed prior to apt-get install.

Notes:

Clean up must be performed in the same RUN step, otherwise it will not affect image size.

You can’t perform that action at this time.