Review a Dockerfile
Purpose
Turn a working Dockerfile into a small, secure, reproducible and cache-friendly one, with each finding justified and a concrete fix.
When to use
- A Dockerfile is submitted in a pull request or shared for review.
- The image is large, builds slowly, or has many scanner findings.
- A service is about to go to production for the first time.
When not to use
- The runtime configuration on the orchestrator is the issue. Use
kubernetes-manifest-review.
- Vulnerabilities in application dependencies are the topic. Use
dependency-vulnerability-review.
- The failure is in the build pipeline, not the file. Use
pipeline-failure-triage.
Inputs
Required:
Optional, improves quality:
- The ignore file (e.g.
.dockerignore), language/build tool, target runtime platform and architecture.
- Current image size, scanner output, build time.
- Organizational base image policy.
If the Dockerfile is missing, ask for it.
Process
- Identify the stack and build type, and whether a multi-stage build is used.
- Base image: official or approved source, minimal variant (slim, distroless, alpine where libc compatible), pinned by tag and digest, not
latest.
- Build stages: separate build tooling from runtime; copy only artifacts into the final stage.
- Layer and cache: dependency manifests copied and installed before source; related
RUN commands combined; package caches cleaned in the same layer; ignore file excludes .git, tests, local env files.
- Security: non-root
USER with fixed UID; no secrets in ARG/ENV/layers (use build secret mounts); no curl | sh without checksum; minimal packages; no SSH or shells needed at runtime where possible; read-only filesystem friendly.
- Reproducibility: pinned package versions or lockfiles; deterministic install commands (
npm ci, pip install --require-hashes, locked restore); explicit platform if multi-arch.
- Runtime correctness: exec-form
ENTRYPOINT/CMD so signals reach the process; proper PID 1 handling; EXPOSE and WORKDIR set; HEALTHCHECK only if the orchestrator does not probe.
- Metadata: OCI labels for source, revision, version.
- Rate each finding Critical/High/Medium/Low and give a corrected snippet; then provide the full revised Dockerfile if changes are substantial.
- Label every inference
[ASSUMPTION] and move unsupported items to open questions. If the goal continues, suggest kubernetes-manifest-review for the runtime configuration or dependency-vulnerability-review for base image and package findings.
Output format
# Dockerfile Review: <image/service>
Summary: <2-3 lines: main risks, expected size/security effect (qualitative)>
| # | Severity | Category | Line | Finding | Fix |
## Revised Dockerfile
```dockerfile
...
```
## Open Questions / Assumptions
Quality checklist
Common pitfalls
- Copying the whole context before installing dependencies, which busts the cache on every change. Copy manifests first.
- Deleting a secret in a later layer; it remains in history. Use build secret mounts.
- Switching to alpine blindly for glibc-dependent runtimes. Verify compatibility or use slim/distroless.
Example
Input: FROM node:latest, COPY . ., RUN npm install, CMD npm start.
Excerpt of output:
| # |
Severity |
Category |
Line |
Finding |
Fix |
| 1 |
High |
Reproducibility |
1 |
Unpinned latest full image |
Pin node:<major>-slim@sha256:... |
| 2 |
High |
Security |
– |
Runs as root |
Add USER node in final stage |
| 3 |
Medium |
Cache |
2-3 |
Source copied before install |
Copy package*.json, npm ci --omit=dev, then copy source |
| 4 |
Medium |
Runtime |
4 |
Shell-form CMD via npm, signals lost |
CMD ["node","server.js"] |
1---2name: dockerfile-review3description: "Reviews a Dockerfile (or Containerfile) for image size, layer and cache efficiency, security hardening and build reproducibility, and returns prioritized findings with corrected snippets. Use when someone shares a Dockerfile for review, an image is large, slow to build or flagged by a scanner, or before a service's first production release."4license: MIT5metadata:6 source: https://skillmd.com/skills/muratdincer/dockerfile-review7 version: "1.0.0"8 language: en9 category: 07-devops-sre10 role: devops-engineer11 area: infrastructure12 title: "Review a Dockerfile"13 related: "kubernetes-manifest-review, pipeline-design, secrets-management-plan, dependency-vulnerability-review"14 prompt: "Review this Dockerfile for our Node.js service. The image is 1.2 GB and the security scan reports 40 vulnerabilities."15---1617# Review a Dockerfile1819## Purpose20Turn a working Dockerfile into a small, secure, reproducible and cache-friendly one, with each finding justified and a concrete fix.2122## When to use23- A Dockerfile is submitted in a pull request or shared for review.24- The image is large, builds slowly, or has many scanner findings.25- A service is about to go to production for the first time.2627## When not to use28- The runtime configuration on the orchestrator is the issue. Use `kubernetes-manifest-review`.29- Vulnerabilities in application dependencies are the topic. Use `dependency-vulnerability-review`.30- The failure is in the build pipeline, not the file. Use `pipeline-failure-triage`.3132## Inputs33Required:34- The Dockerfile text.3536Optional, improves quality:37- The ignore file (e.g. `.dockerignore`), language/build tool, target runtime platform and architecture.38- Current image size, scanner output, build time.39- Organizational base image policy.4041If the Dockerfile is missing, ask for it.4243## Process441. Identify the stack and build type, and whether a multi-stage build is used.452. Base image: official or approved source, minimal variant (slim, distroless, alpine where libc compatible), pinned by tag and digest, not `latest`.463. Build stages: separate build tooling from runtime; copy only artifacts into the final stage.474. Layer and cache: dependency manifests copied and installed before source; related `RUN` commands combined; package caches cleaned in the same layer; ignore file excludes `.git`, tests, local env files.485. Security: non-root `USER` with fixed UID; no secrets in `ARG`/`ENV`/layers (use build secret mounts); no `curl | sh` without checksum; minimal packages; no SSH or shells needed at runtime where possible; read-only filesystem friendly.496. Reproducibility: pinned package versions or lockfiles; deterministic install commands (`npm ci`, `pip install --require-hashes`, locked restore); explicit platform if multi-arch.507. Runtime correctness: exec-form `ENTRYPOINT`/`CMD` so signals reach the process; proper PID 1 handling; `EXPOSE` and `WORKDIR` set; `HEALTHCHECK` only if the orchestrator does not probe.518. Metadata: OCI labels for source, revision, version.529. Rate each finding Critical/High/Medium/Low and give a corrected snippet; then provide the full revised Dockerfile if changes are substantial.5310. Label every inference `[ASSUMPTION]` and move unsupported items to open questions. If the goal continues, suggest `kubernetes-manifest-review` for the runtime configuration or `dependency-vulnerability-review` for base image and package findings.5455## Output format56````markdown57# Dockerfile Review: <image/service>58Summary: <2-3 lines: main risks, expected size/security effect (qualitative)>59| # | Severity | Category | Line | Finding | Fix |60## Revised Dockerfile61```dockerfile62...63```64## Open Questions / Assumptions65````6667## Quality checklist68- [ ] Every finding references a line or instruction in the input.69- [ ] The final stage runs as non-root and contains no build tooling or secrets.70- [ ] Base image is pinned; no `latest`.71- [ ] Revised file is syntactically valid and preserves the original behavior.72- [ ] No invented size or CVE numbers; expected effects are qualitative unless data was given.73- [ ] All checks pass; if any fails, revise the output and re-run this checklist before answering.7475## Common pitfalls76- Copying the whole context before installing dependencies, which busts the cache on every change. Copy manifests first.77- Deleting a secret in a later layer; it remains in history. Use build secret mounts.78- Switching to alpine blindly for glibc-dependent runtimes. Verify compatibility or use slim/distroless.7980## Example81Input: `FROM node:latest`, `COPY . .`, `RUN npm install`, `CMD npm start`.8283Excerpt of output:84| # | Severity | Category | Line | Finding | Fix |85|---|---|---|---|---|---|86| 1 | High | Reproducibility | 1 | Unpinned `latest` full image | Pin `node:<major>-slim@sha256:...` |87| 2 | High | Security | – | Runs as root | Add `USER node` in final stage |88| 3 | Medium | Cache | 2-3 | Source copied before install | Copy `package*.json`, `npm ci --omit=dev`, then copy source |89| 4 | Medium | Runtime | 4 | Shell-form CMD via npm, signals lost | `CMD ["node","server.js"]` |