8 DL3009
londondaintta edited this page 2023-12-13 16:14:26 +00:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Delete the apt-get lists after installing something.

Problematic code:

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

Correct code:

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

Rationale:

https://docs.docker.com/develop/develop-images/instructions/#apt-get

In addition, when you clean up the apt cache by removing /var/lib/apt/lists it reduces the image size, since the apt cache isnt stored in a layer. Since the RUN statement starts with apt-get update, the package cache is always refreshed prior to apt-get install.

Notes:

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