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