From 466346681ed33d03200bc169561991d914278917 Mon Sep 17 00:00:00 2001 From: Rudy Regazzoni <110470341+rudy-regazzoni-sonarsource@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:49:05 +0100 Subject: [PATCH] Address review comments --- rules/S6587/docker/rule.adoc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rules/S6587/docker/rule.adoc b/rules/S6587/docker/rule.adoc index e86b7528c4b..4744a8adb5a 100644 --- a/rules/S6587/docker/rule.adoc +++ b/rules/S6587/docker/rule.adoc @@ -131,19 +131,18 @@ They are not removed by the `clean` command, so they need to be removed manually Alternatively, store the cache in a dedicated cache mount. A cache mount can be created by adding a flag `--mount type=cache` to the `RUN` command. + This will store the cache in a Docker volume, which will be persisted between builds making the build faster. -Also, each `RUN` instruction creates a new layer, and any changes made in one layer are not visible in the next. Thus, the cache should be removed in the same layer as the installation in the same `RUN` instruction. +Also, each `RUN` instruction creates a new layer, and any changes made in one layer are not visible in the next. Thus, the cache should be removed in the same layer (i.e., the same `RUN` instruction) as the installation. The following code incorrectly cleans the cache: [source,docker] ---- -RUN apt-get install -y git -RUN apt-get clean && rm -rf /var/lib/apt/lists/* +RUN apt-get install nginx +RUN apt-get clean ---- It should be written as: [source,docker] ---- -RUN apt-get install -y git \ - && apt-get clean && rm -rf /var/lib/apt/lists/* +RUN apt-get install nginx && apt-get clean ---- == Resources