This product is not supported for your selected Datadog site. ().
Metadata
ID:docker-best-practices/use-absolute-paths
Language: Docker
Severity: Warning
Category: Best Practices
Description
This rule encourages the use of absolute paths or the WORKDIR instruction to change directories within Dockerfiles instead of chaining commands with cd. Using relative paths combined with cd in a single RUN instruction can lead to less readable and more error-prone code. It also makes it harder to track the current working directory during image builds.
To comply, either set the working directory explicitly using WORKDIR /path/to/directory before running commands or use absolute paths in instructions like RUN cp /source/file /destination/path. Avoid combining cd with other commands in a single RUN line, as this can cause unexpected behavior and complicate debugging.
Non-Compliant Code Examples
FROM busyboxRUNcd /usr/src/app && cp somedir/somefile ./someDirInUsrSrcApp/
FROM busyboxRUNcd /usr/src/app && git clone git@github.com:lukasmartinelli/hadolint.git
Compliant Code Examples
FROM busyboxRUN cp somedir/somefile /usr/src/app/someDirInUsrSrcApp/
FROM busyboxWORKDIR /usr/src/appRUN git clone git@github.com:lukasmartinelli/hadolint.git
Seamless integrations. Try Datadog Code Security
Datadog Code Security
Try this rule and analyze your code with Datadog Code Security
How to use this rule
1
2
rulesets:- docker-best-practices # Rules to enforce Docker best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Security scans to your CI pipelines