rspec/rules/S7021/docker/rule.adoc

54 lines
1.3 KiB
Plaintext

`WORKDIR` instructions should be used with an absolute path for clarity and reliability.
== Why is this an issue?
The `WORKDIR` instruction defines the working directory for any `RUN`, `CMD`, `ENTRYPOINT`, `COPY`, and `ADD` instructions that follow in the Dockerfile. +
Using absolute paths helps to avoid any confusion or unexpected behavior that could arise, for example after changing the current directory in one of the previous instructions.
== How to fix it
=== Code examples
==== Noncompliant code example
[source,docker,diff-id=1,diff-type=noncompliant]
----
WORKDIR my_working_folder
WORKDIR .\\my_working_folder
----
==== Compliant solution
[source,docker,diff-id=1,diff-type=compliant]
----
WORKDIR /images/my_working_folder
WORKDIR C:\\images\\my_working_folder
----
== Resources
=== Documentation
* Docker docs - https://docs.docker.com/build/building/best-practices/#workdir[Building best practices - WORKDIR]
=== Related rules
* S6597 - `WORKDIR` instruction should be used instead of `cd` commands
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use an absolute path instead of this relative path when defining the WORKDIR.
=== Highlighting
Highlight the relative path in the WORKDIR instruction.
'''
endif::env-github,rspecator-view[]