Review relative WORKDIR paths

Establish an explicit absolute working-directory path.

Description

A relative WORKDIR starts from the previous working directory, which can come from the base image.

Potential impact

A change to that base directory can move later commands or COPY destinations unexpectedly.

Remediation

Start each stage with an absolute WORKDIR. For any later relative WORKDIR, check the resulting path.

Examples

Both examples copy to /usr/src/app. The single absolute WORKDIR makes that destination explicit.

Before

dockerfile
FROM node:22-alpine

WORKDIR /usr/src
WORKDIR app
COPY . .

After

dockerfile
FROM node:22-alpine

WORKDIR /usr/src/app
COPY . .

References