Skip to content
Ross Smith II edited this page Mar 9, 2023 · 3 revisions

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.

Exceptions:

When using environment replacements.

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

Contraindications

WORKDIR is not recommended in GitHub actions.