Skip to main content

DL3045: COPY to a relative destination without WORKDIR set

Warning Maintainability

Why This Matters

When COPY uses a relative destination (e.g., COPY . app/) and no WORKDIR has been set in the current build stage, the destination resolves relative to the filesystem root (/). This is usually unintentional and makes the Dockerfile fragile because the behavior depends on the base image default WORKDIR. Files end up in unexpected locations and builds break in confusing ways. Set WORKDIR before using relative paths.

How to Fix

Set WORKDIR before COPY with relative destination

Before (incorrect)

FROM node:20
COPY . app/

After (correct)

FROM node:20
WORKDIR /app
COPY . .

Rule Details

Rule Code
DL3045
Severity
Warning
Category
Maintainability

Related Rules