diff --git a/rules/S6587/docker/rule.adoc b/rules/S6587/docker/rule.adoc index 67b13a3b18a..4744a8adb5a 100644 --- a/rules/S6587/docker/rule.adoc +++ b/rules/S6587/docker/rule.adoc @@ -131,6 +131,20 @@ 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 (i.e., the same `RUN` instruction) as the installation. + +The following code incorrectly cleans the cache: +[source,docker] +---- +RUN apt-get install nginx +RUN apt-get clean +---- +It should be written as: +[source,docker] +---- +RUN apt-get install nginx && apt-get clean +---- + == Resources === Documentation