4 DL3000
Moritz Röhrich edited this page 2025-08-12 13:10:16 +02:00

Use absolute WORKDIR.

Problematic code:

FROM busybox
WORKDIR usr/src/app

Correct code:

FROM busybox
WORKDIR /usr/src/app

Rationale:

By using absolute paths you will not run into problems when a previous WORKDIR instruction changes. You also often times don't know the WORKDIR context of your base container.

See also: https://docs.docker.com/reference/build-checks/workdir-relative-path/

Exceptions:

When using environment replacements.

FROM busybox
ENV foo /bar
WORKDIR ${foo}   # WORKDIR /bar

Contraindications

WORKDIR is not recommended in GitHub actions.