From 32c720335679b30d9042fdf788f45b8b8f1ad70d Mon Sep 17 00:00:00 2001 From: Rudy Regazzoni <110470341+rudy-regazzoni-sonarsource@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:09:50 +0100 Subject: [PATCH] SONARIAC-1701 Update RSPEC description for S6587 --- rules/S6587/docker/rule.adoc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rules/S6587/docker/rule.adoc b/rules/S6587/docker/rule.adoc index 67b13a3b18a..e86b7528c4b 100644 --- a/rules/S6587/docker/rule.adoc +++ b/rules/S6587/docker/rule.adoc @@ -131,6 +131,21 @@ 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. + +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/* +---- +It should be written as: +[source,docker] +---- +RUN apt-get install -y git \ + && apt-get clean && rm -rf /var/lib/apt/lists/* +---- + == Resources === Documentation