Dockerfile Security & Best Practices Linter
Audit Dockerfiles for security pitfalls, unpinned base images, root user execution, inefficient layer caching, and multi-stage build opportunities with 100% client-side analysis.
Container Executes as Root User (UID 0)
The final production image does not specify a non-root USER instruction.
RUN addgroup -S appgroup && adduser -S appuser -G appgroup USER appuser
Unknown Instruction
Unknown Dockerfile instruction. Verify command syntax and spelling.
Insecure Remote Script Piped to Shell
Piping curl or wget directly into shell ('curl ... | bash') is unsafe.
# Download script, verify SHA256 checksum, then execute
Using ':latest' Base Image Tag
Avoid using ':latest' tag for base images in production Dockerfiles.
FROM node:<exact-version>
Multi-Stage Build Opportunity Detected
Build toolchains and compilers detected inside a single-stage Dockerfile.
# Convert to multi-stage: FROM base AS builder ... FROM runtime ... COPY --from=builder
Relative WORKDIR Path
Use absolute paths for WORKDIR instructions instead of relative directory paths.
WORKDIR /app
Standalone 'apt-get update' Instruction
'apt-get update' should be chained in the same RUN layer with 'apt-get install'.
Apt Package Cache Not Cleaned Up
Delete package lists ('rm -rf /var/lib/apt/lists/*') after apt-get install.
RUN apt-get install -y curl git python3 && rm -rf /var/lib/apt/lists/*
Missing HEALTHCHECK Instruction in Final Stage
No HEALTHCHECK instruction defined for container health monitoring.
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8080/health || exit 1
Use COPY Instead of ADD for Local Files
Use COPY rather than ADD when moving local files and folders into containers.
COPY . .
Missing '--no-install-recommends' in apt-get
Add '--no-install-recommends' to prevent installing non-essential packages.
RUN apt-get install -y --no-install-recommends -y curl git python3
Multiple Consecutive RUN Instructions
Consolidate consecutive RUN instructions using '&& ' to reduce image layers.
Piped Command Without Shell 'pipefail' Option
Pipes in RUN instructions should enable pipefail.
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Multiple Consecutive RUN Instructions
Consolidate consecutive RUN instructions using '&& ' to reduce image layers.
Multiple Consecutive RUN Instructions
Consolidate consecutive RUN instructions using '&& ' to reduce image layers.
Privileged Port (< 1024) Exposed
Exposed port is below 1024, traditionally requiring root privileges.
Shell Form Used for ENTRYPOINT
ENTRYPOINT uses shell syntax string instead of JSON exec array.
CMD ["npm","start"]
Export Dockerfile & CI/CD Audit Report
Download hardened configurations or copy standard Markdown reports for PR comments and security audits.
Zero-Knowledge Local Execution
All data processing, parsing, and compilation execute strictly inside your local browser memory. Zero external server uploads.
Instant Client-Side Engine
Instant real-time reactive computation delivers immediate feedback on every keystroke with zero network latency.
Production Standards & Compliance
Strictly validates syntax, edge cases, and formatting rules for dependable production output.
Dockerfile Security & Best Practices Linter — Reference Guide
Audit Dockerfiles for security pitfalls, unpinned base images, root user execution, inefficient layer caching, and multi-stage build opportunities with 100% client-side analysis.
Key Parameters & Controls
| Parameter | Type / Unit | Description | Default |
|---|---|---|---|
| FROM | directive | Defines the base image. Should include an explicit version tag or immutable SHA256 digest instead of ':latest'. | Required |
| USER | directive | Sets the UID/GID for subsequent commands and container runtime. Should specify a non-root system user. | Required (Security) |
| RUN | directive | Executes shell commands to install packages. Should combine package manager cleanup (e.g. apt-get clean) in the same layer. | Optional |
| COPY | directive | Transfers files from build context. Preferred over ADD for standard files; supports --chown flag. | Optional |
Pro Tips & Best Practices
Use 'node:20-alpine@sha256:...' to guarantee immutable, reproducible builds that cannot be affected by upstream image changes.
Chain 'apt-get update && apt-get install -y --no-install-recommends pkg && rm -rf /var/lib/apt/lists/*' in a single RUN to prevent layer bloat.
Compile code in an SDK container stage and copy only the final binary into a minimal distroless or alpine runtime stage.
Common Gotchas & Troubleshooting
⚠️Permission denied error in container when running as non-root USER
Use 'COPY --chown=appuser:appgroup' when transferring files into the image so the non-root user owns the working directory.
⚠️Docker build cache repeatedly invalidated on every commit
Copy package.json or dependency manifests first, run the dependency install step, and only copy the source code in later stages.
Frequently Asked Questions
Why should containers never run as the root user?▼
Running as root increases the blast radius of container breakouts. If an attacker breaches the application, they inherit root capabilities on the container and potentially the host kernel.
Why is the ':latest' tag considered harmful in production Dockerfiles?▼
The ':latest' tag is mutable and unpredictable. Builds executed across different days or environments can pull completely different OS versions and breaking dependency updates.
What is the difference between COPY and ADD?▼
COPY is predictable and only copies local files. ADD automatically unpacks tar archives and can fetch remote URLs, creating hidden security and caching risks.
How do multi-stage builds reduce image size and improve security?▼
Multi-stage builds leave compilers, SDKs, and build secrets behind in intermediate stages, keeping only the final executable in a tiny runtime container without shell or package tools.
Related Tools & Utilities
All Tools →Create hardened, lightweight multi-stage Dockerfiles for Node.js, Golang, Python, Rust, and Java with non-root security and cache optimization.
Validate docker-compose.yml files locally for YAML syntax bugs, port conflicts, missing volumes, and cyclic dependencies.
Validate Kubernetes Deployment, Pod, Service, Ingress, and ConfigMap manifests against official Kubernetes OpenAPI v1.28+ schemas. Catch missing apiVersion fields, container resource limits, and privilege escalation risks.
Create fine-grained Kubernetes NetworkPolicy YAML manifests with Ingress/Egress CIDR blocks, podSelector labels, namespaceSelector, and port restrictions.
Visually build, audit, and validate strict Content-Security-Policy (CSP) headers with nonce/hash support, script-src, frame-ancestors, and server export.
Validate XML sitemaps and sitemap index files instantly. Check 50k URL limits, W3C Datetime syntax, hreflang tags, media schemas, and Google Search Console errors.