Review yum installation cache cleanup

Install packages and clean the yum cache in the same RUN.

Description

yum install can leave package metadata and caches in the image.

Potential impact

Unused caches take up registry space and make images slower to pull. Cleaning a later layer leaves the installation layer unchanged.

Remediation

After yum install succeeds, run yum clean all in the same RUN. Check the final size and keep the installed packages updated.

Examples

The CentOS 7 example illustrates the order of commands. For production, use a supported base and a repository that provides nginx.

Before

dockerfile
FROM centos:7

RUN yum install -y nginx

After

dockerfile
FROM centos:7

RUN yum install -y nginx \
    && yum clean all

References