require-dockerignore-file
Require .dockerignore when a repository-root Dockerfile is present.
Targeted pattern scopeâ
- Repositories that commit a root
Dockerfilewithout a matching.dockerignorefile.
What this rule reportsâ
This rule reports repositories with a root Dockerfile that do not also commit
.dockerignore.
Why this rule existsâ
Without .dockerignore, Docker sends the entire repository as build context.
That increases build time and can accidentally include credentials, Git
metadata, caches, and other files that should never reach the image build.
â Incorrectâ
FROM node:22-alpine
WORKDIR /app
COPY . .
RUN npm ci
â Correctâ
FROM node:22-alpine
WORKDIR /app
COPY . .
RUN npm ci
# .dockerignore
node_modules
.git
.env
coverage
When not to use itâ
Disable this rule only if the repository intentionally wants the full build context and that trade-off is understood.
Rule catalog ID: R069