high · dockerfile/copying-secrets-into-image
Secrets copied into the image
Secrets copied into layers remain in image history even if deleted later.
Why it breaks the cache
Copied files stay in earlier image layers even if a later instruction deletes them.
Bad Dockerfile
COPY .env /app/
COPY id_rsa /root/.ssh/
Good Dockerfile
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
CLI
layerlint rules explain copying-secrets-into-image