Skip to main content
Relative workdir can have unexpected results if the base image changes.

Description

When specifying WORKDIR 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 (assumes WORKDIR in base image is /):
Good:

Auto-fix

Replaces the relative WORKDIR 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 actual WORKDIR from the registry (FixSafe, applied with --fix). Chained relative WORKDIRs are resolved cumulatively.

Supersedes

Reference