| Property | Value |
|---|---|
| Severity | Warning |
| Category | Best Practice |
| Default | Enabled |
| Auto-fix | Yes (suggestion --fix-unsafe; safe with --slow-checks) |
Description
When specifyingWORKDIR in a build stage, you can use an absolute path, like
/build, or a relative path, like ./build. Using a relative path means that
the working directory is relative to whatever the previous working directory was.
This rule warns if you use WORKDIR with a relative path without first
specifying an absolute path in the same Dockerfile. The rationale is that using
a relative working directory for a base image built externally is prone to
breaking, since the working directory may change upstream without warning.
Examples
Bad (assumesWORKDIR in base image is /):
Auto-fix
Replaces the relativeWORKDIR with an absolute path.
- Fast path (no registry access): resolves against
/as a default (FixSuggestion, requires--fix-unsafe). - With
--slow-checks: resolves against the base image’s actualWORKDIRfrom the registry (FixSafe, applied with--fix). Chained relative WORKDIRs are resolved cumulatively.