Dockerfile Linter & Analyzer
Analyze Dockerfiles for syntax errors, security risks, Docker best practices, image optimization opportunities, and build-caching improvements directly in your browser.
- '.env' is not excluded in .dockerignore. Secret environment files may enter the build context.
- '.git' is not excluded in .dockerignore, increasing build context upload time.
- 'node_modules' is not excluded in .dockerignore, potentially overriding clean container dependencies.
The base image uses the ':latest' tag, which can change unpredictably over time.
FROM node:22-alpine
The Dockerfile explicitly declares 'USER root'.
MAINTAINER is deprecated in modern Dockerfile specifications.
LABEL maintainer="John Doe <john@example.com>"
Sensitive key 'API_KEY' defined with a hardcoded value in ENV.
# Remove hardcoded secret default from ENV # Pass API_KEY via docker run -e API_KEY=... or Docker Secret Mount
Sensitive key 'DATABASE_PASSWORD' defined with a hardcoded value in ENV.
# Remove hardcoded secret default from ENV # Pass DATABASE_PASSWORD via docker run -e DATABASE_PASSWORD=... or Docker Secret Mount
ADD is downloading a remote URL directly.
The instruction copies files matching secret patterns (e.g. .env, id_rsa, credentials).
'apt-get update' is executed in its own layer without installing packages.
RUN apt-get update && apt-get install -y --no-install-recommends <packages> && rm -rf /var/lib/apt/lists/*
Package installation does not delete temporary package index lists.
Executing a remote script via 'curl | sh' without prior checksum or integrity verification.
Setting 777 permissions grants read, write, and execute access to all users.
CMD uses shell form instead of JSON-array exec form.
Copying application source code before installing dependencies breaks Docker layer caching.
Found 4 separate RUN instructions in sequence in stage 1.
No HEALTHCHECK instruction was detected in the Dockerfile.
How to Use
How to Lint a Dockerfile Online
Linting a Dockerfile before invoking docker build prevents failed CI/CD pipelines, optimizes layer caching, and eliminates security vulnerabilities before container images are published to container registries.
- Input Your Dockerfile: Paste your Dockerfile code directly into the editor, upload an existing
Dockerfilefrom your file system, or load one of the built-in scenarios (Simple Valid, Common Problems, Multi-Stage). - Configure .dockerignore (Optional): Switch to the
.dockerignoretab to verify that sensitive files (.env, private keys) and local caches (node_modules,.git) are properly excluded from the build context. - Inspect the Dockerfile Score & Findings: Review your overall 0–100 quality score and browse findings grouped into Errors, Warnings, and Informational recommendations.
- Navigate to Source Lines: Click on any finding or line number tag to focus and highlight the exact instruction inside the editor.
- Apply Remediation: Review suggested fixes, copy the corrected instructions, or export a complete JSON audit report or sanitized Dockerfile with masked secrets.
Common Dockerfile Mistakes
Static analysis identifies subtle syntax errors and architectural anti-patterns that degrade container reproducibility, increase image size, and expose security vulnerabilities:
Using FROM node:latest or untagged base images causes non-reproducible builds. When the upstream image updates, unexpected breaking changes or new CVE vulnerabilities can silently enter production. Always pin explicit versions (e.g. node:22-alpine) or SHA256 digests.
Placing COPY . . before package installation commands (npm install, pip install) invalidates Docker's build cache on every single source code edit. Always copy manifest files (package*.json) first, install dependencies, and then copy application code.
Instructions like WORKDIR app or WORKDIR ./app depend on the prior working directory established by the base image or parent stage. Best practices require absolute paths (e.g. WORKDIR /app) to ensure predictable directory hierarchies.
Shell-form CMD node server.js wraps the application process inside /bin/sh -c as PID 1, intercepting Unix signals and preventing graceful shutdown (SIGTERM). Exec form CMD ["node", "server.js"] runs the application directly as PID 1.
The ADD instruction automatically extracts local tarballs and fetches remote URLs without checksum verification. Use COPY for standard local file transfers, and use RUN curl or wget with hash checks for remote downloads.
Values hardcoded in ENV or ARG instructions persist permanently across intermediate image layers and can be extracted by anyone with read access to the image. Never embed API keys, database credentials, or tokens in your Dockerfile.
Dockerfile Security Best Practices
Hardening Dockerfiles is the foundation of container security. Following the principle of least privilege ensures that if an application process is compromised, the attacker cannot trivially escalate privileges to the container host.
By default, Docker executes instructions and runtime processes as root (UID 0). Always create a dedicated system user and switch to it before the CMD or ENTRYPOINT instruction:
# Alpine Linux: RUN adduser -D -u 1000 appuser && chown -R appuser:appuser /app USER appuser # Debian / Ubuntu: RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app USER appuser
Do not pass credentials via build arguments (ARG) or environment variables (ENV). Use Docker BuildKit secret mounts (RUN --mount=type=secret,id=npmrc ...) so credentials are accessible only during command execution and never stored in image layers.
Never pipe unverified remote scripts directly to a shell (curl ... | sh). Download scripts, verify their cryptographic SHA256 checksum or GPG signature, and run them locally. Restrict file permissions with specific masks (e.g. chmod 755 for directories, chmod 644 for files) rather than blanket chmod 777.
Multi-Stage Docker Builds
Multi-stage Docker builds allow you to use multiple FROM instructions within a single Dockerfile. You can compile binaries, download heavy SDKs, and bundle frontend code in early stages, copying only the final lean artifacts into a minimal production image.
# Stage 1: Build & Compile FROM golang:1.23-alpine AS builder WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /bin/app . # Stage 2: Minimal Runtime Image FROM alpine:3.20 AS production RUN apk add --no-cache ca-certificates tzdata RUN adduser -D -u 1000 appuser WORKDIR /app COPY --from=builder /bin/app /app/app USER appuser EXPOSE 8080 HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:8080/health || exit 1 ENTRYPOINT ["/app/app"]
In this example, the Go compiler and build cache stay in Stage 1, while the final production container is only ~15MB.
Dockerfile Linter vs. Docker Build Checks vs. Hadolint
Understanding how different linting and validation tools complement each other helps you establish an effective container development workflow:
| Tool | Execution Environment | Primary Role | Key Strengths |
|---|---|---|---|
| ToolMono Dockerfile Linter | Browser-local (100% Client-Side) | Instant pre-check, security audit & education | No install required, line-level jump, .dockerignore cross-analysis, secret masking |
| Hadolint | CLI / GitHub Actions / Pre-commit | Automated CI/CD gatekeeper | Deep ShellCheck AST parsing for complex RUN scripts, configurable rule ignores |
| Docker Build Checks | Docker BuildKit CLI (v24+) | Engine-level build warnings | Integrated directly into docker build --check, catches engine deprecations |
* Note: ToolMono is an independent static analysis tool designed for fast browser-based code inspection. It does not replace running docker build or executing vulnerability scanners like Trivy or Grype on compiled images.
Frequently Asked Questions
Authoritative References & Standards
Consult official containerization standards and security guidelines:
Docker Documentation: Dockerfile Reference
Official Docker standard specification for all Dockerfile instructions, syntax, and build parser directives.
Docker Documentation: Best practices for writing Dockerfiles
Authoritative Docker guidelines for layer caching, multi-stage builds, and minimal image sizing.
OWASP Docker Security Cheat Sheet
Industry security standards for non-root users, secret management, and container hardening.
CIS Docker Benchmark Standard
Center for Internet Security consensus benchmarks for container image configuration.
Related Tools
Browse all toolsFree Compose Visualizer
Visualize Docker Compose files as interactive service dependency graphs and architecture diagrams. Inspect networks, volumes, ports, and dependencies directly in your browser.
.env Validator
Validate .env files, detect syntax errors, duplicate keys, empty values, potential secrets, compare environments, find missing variables, and review configuration drift.
Robots.txt Validator
Validate and test robots.txt files online. Check syntax, Allow/Disallow rules, Googlebot access, URL crawlability, sitemaps, AI crawlers, and SEO issues with exact winning-rule explanations.
AI.txt Validator
Validate AI.txt syntax, directives, and policy rules directly in your browser. Find line-level errors, review compatibility warnings, and generate a clean AI.txt file.