Building Container Images
From Leo's Notes
This page was last edited on 8 November 2021, at 05:25.
Tips
RUN commands
Try to bundle multiple RUN commands together to reduce the number of container image layers and their overall size. Concatenating multiple commands with && or ; (with set-x, which stops the script when a non zero exit code is returned).
RUN set -ex; \
yum -y install vim; \
yum clean all
## or,
RUN yum -y install vim && yum clean all
Alternatively, use multi-staged builds (https://docs.docker.com/develop/develop-images/multistage-build/) to bundle the results of multiple layers into one.
Yum/dnf-based package managers
Yum or dnf package managers are used on Red Hat based distros.
- Install packages with
yum -y installto avoid prompts yum -y clean all, and clean up cachesrm -rf /var/cache- Apt-based package managers
Apt-based package managers are used on Ubuntu and Debian based distros.
- Set
DEBIAN_FRONTEND=noninteractiveto prevent some packages from prompting interactive input (tzdatafor example), which leads to indefinite waiting for an user input rm -rf /var/lib/apt/lists/*afterwards