This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the containerization category.
Last Updated: 2025-10-31
Reduce number of docker layers by using && in run commands
The version has 3 layers
RUN apt-get update \
  && apt-get install -y \
    unzip \
    neovim \
    ripgrep \
    curl \
RUN curl -sS https://getcomposer.org/installer | \
     php -- --install-dir=/usr/local/bin --filename=composer
RUN rm -rf /var/lib/apt/lists/
vs. the following, which has one layer only (and is therefore less bulkier)
RUN apt-get update \
  && apt-get install -y \
    unzip \
    neovim \
    ripgrep \
    curl \
  && curl -sS https://getcomposer.org/installer | \
     php -- --install-dir=/usr/local/bin --filename=composer \
  && rm -rf /var/lib/apt/lists/