Skip to content

Skip hadolint DL3059 on build stages in multi-stage Dockerfile #1056

@Glenn-Terjesen

Description

@Glenn-Terjesen
  • [ ] This is a bug report
  • This is a feature request
  • [x ] I searched existing issues before opening this one

Expected behavior

In a multi-stage Dockerfile, in the build stage(s) we want as many RUN instructions as possible to cache the steps.

https://docs.docker.com/build/building/multi-stage/

Actual behavior

hadolint scans all parts of the file and not only the run stage.

Steps to reproduce the behavior

Look at Dockerfile bellow.

Error: Dockerfile:11 DL3059 info: Multiple consecutive RUN instructions. Consider consolidation.
Error: Dockerfile:12 DL3059 info: Multiple consecutive RUN instructions. Consider consolidation.
Error: Dockerfile:13 DL3059 info: Multiple consecutive RUN instructions. Consider consolidation.

Output of hadolint --version or
docker run --rm hadolint/hadolint hadolint --version or
docker run --rm ghcr.io/hadolint/hadolint hadolint --version:

hadolint/[email protected]
(GitHub Actions.. )

Dockerfile (if relevant)

FROM node:18.20.4-alpine AS build
WORKDIR /usr/src/app
COPY . .
RUN npm install
RUN npm run lint
RUN CI=true npm run test
RUN npm run build

FROM node:18.20.4-alpine 
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production --ignore-scripts
COPY --from=build /usr/src/app/build .
CMD ["npm", "run", "server"]

Additional environment details (OS, stack version, etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions