Docker

Docker

Made by DeepSource

COPY to a relative destination without WORKDIR set DOK-W1006

Bug risk
Major

While COPYing to a relative path is not problematic per sé, errors happen, when changes are introduced to the WORKDIR without updating the destination of the COPY command.

Since it is easy to overlook this relationship, we raise if no WORKDIR is set and COPY has a relative destination. This case is error prone and either setting the COPY-destination absolute or the WORKDIR explicitly will reduce the probability of having an error.

It is assumed, that when a WORKDIR is set, the programmer will make sure it works well together with the destination of the COPY statements.

Bad Practice

FROM scratch
COPY foo bar

Recommended

FROM scratch
COPY foo /bar

# or,

FROM scratch
WORKDIR /
COPY foo bar