Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy-regazzoni-sonarsource committed Dec 9, 2024
1 parent 32c7203 commit b8a2d8a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions rules/S6587/docker/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8a2d8a

Please sign in to comment.