Delete the apt-get lists after installing something
51ARG DOCKER_ARCH=x86_64
52ARG KUBECTL_ARCH=amd64
53
54RUN apt-get -qq update && apt-get -qq -y install curl default-mysql-client postgresql-client redis-tools telnet skopeo55
56SHELL ["/bin/bash", "-o", "pipefail", "-c"]
57
Description
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
.
You can read more about this here.
Note: Clean up must be performed in the same RUN step, otherwise it will not affect image size.
Bad Practice
RUN apt-get update && apt-get install -y python
Recommended
RUN apt-get update && apt-get install -y python \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Exceptions
The official Debian and Ubuntu images are configured to automatically run apt clean
, so explicitly invoking apt clean
is not necessary there.