Dockerfile Layer Optimizer
Check a Dockerfile for layer, cache and multi-stage suggestions. Everything runs in your browser.
Dockerfile
8 lines · 146 charsFindings and suggestion
9 findings · 5 filesystem layers in the final stageFindings
- Base image 'node:latest' is not pinnedwarning · line 1
Consider a version tag or digest instead of latest or an implicit tag, so rebuilds start from the same base.
- Consider a multi-stage buildinfo · line 1
Compile in a builder stage and copy only runtime artifacts into the final image so build tools stay out of it.
- Final stage runs as rootinfo · line 1
Consider adding a non-root USER before CMD/ENTRYPOINT.
- Source is copied before dependencies are installedinfo · line 3
Consider copying only the dependency manifest first, installing, then copying the source, so edits to source files do not re-run the install.
- Broad build-context copy detectedinfo · line 3
Consider a .dockerignore, and copy dependency manifests before source files so cache keys stay stable.
- apt-get update is separated from installwarning · line 4
The package index becomes stale or invalidates a cache layer; consider update and install in one RUN.
- Consecutive RUN layers can be combinedinfo · line 4
Combining related commands with && reduces layers; the trade-off is coarser caching, since any change re-runs the whole combined RUN.
- apt package lists are not cleanedwarning · line 5
Removing /var/lib/apt/lists/* in the same RUN keeps the index out of this layer; a rm in a later RUN does not shrink earlier layers.
- apt-get install without --no-install-recommendsinfo · line 5
Consider --no-install-recommends to avoid pulling optional packages.
Suggested Dockerfile
- Combined 4 consecutive RUN instructions starting at line 4 into one.
- Added rm -rf /var/lib/apt/lists/* to the RUN at line 4 (same layer as apt-get install).
FROM node:latest AS builder
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y curl && npm ci && npm run build && rm -rf /var/lib/apt/lists/*
CMD ["npm", "start"]Examples
Separated apt update and install
FROM node:22
RUN apt-get update
RUN apt-get install -y curlwarnings: apt-update-layer (line 2), apt-cache (line 3), run-combine infoupdate without install in the same RUN triggers apt-update-layer; the install layer without list cleanup triggers apt-cache.
Optimizer merges RUN layers
optimizeDockerfile("FROM node:22\nRUN apt-get update && apt-get install -y curl\nRUN npm ci")RUN apt-get update && apt-get install -y curl && npm ci && rm -rf /var/lib/apt/lists/*Consecutive RUN commands join with && and the missing apt list cleanup is appended to the merged layer.
About this tool
Dockerfile Layer Optimizer parses a Dockerfile with parseDockerfile(source) into instructions and named stages (FROM ... AS <name>, with --platform= prefixes understood and backslash continuations joined), then analyzeDockerfile(source) reports ordered findings: empty and missing-from errors, an only-from error for a bare base image, unpinned-base warnings for latest or implicit tags, apt-update-layer warnings when apt-get update runs without install in the same RUN, apt-cache warnings when apt-get install omits rm -rf /var/lib/apt/lists/*, plus dockerignore, run-combine, and multi-stage info hints.
Every analysis also returns a layerCount over layer-producing instructions, a cacheEstimate (High for multi-stage builds, Medium otherwise with a reason), and an optimized Dockerfile string from optimizeDockerfile(source): consecutive RUN lines merge with && and any apt-get install layer without cleanup gains && rm -rf /var/lib/apt/lists/*. Findings sort deterministically by line, then severity (error, warning, info), then rule name.
Multi-stage awareness is descriptive, not prescriptive: COPY --from=<stage> lines parse as ordinary COPY instructions, and the multi-stage info hint only fires when build-tool RUN commands (npm, pnpm, yarn, go, cargo, mvn, gradle with build/install/compile) appear in a single-stage file — a file that already has two or more stages never gets that hint.
How to use this tool
Paste the Dockerfile
Call analyzeDockerfile(source): parseDockerfile splits the input into instructions and stages while skipping blanks and # comments and ignoring unknown keywords.
Read findings in order
Findings arrive sorted by line, severity, then rule — fix error rules (empty, missing-from, only-from) before warning rules (unpinned-base, apt-update-layer, apt-cache).
Combine apt steps
Move apt-get update and apt-get install into one RUN and end it with rm -rf /var/lib/apt/lists/* to clear both the apt-update-layer and apt-cache warnings.
Apply the optimizer
Copy the optimized field (optimizeDockerfile output): consecutive RUN layers are already merged with && and apt cleanup appended where it was missing.
Use cases
Slimming Node and Debian-based images
Find apt-cache findings and apply the optimizer's rm -rf cleanup to stop shipping package indexes in the final layer.
Stabilizing layer caching
Use run-combine and dockerignore hints to order dependency installs before broad COPY . /app steps that invalidate the cache.
Reviewing multi-stage conversions
Check whether the multi-stage info hint fires on a single-stage build with compile steps, then split into builder and runtime stages.
Common mistakes
Mistake:Pinning nothing and building FROM node:latest.
Fix:Use an explicit version tag or digest (e.g. node:22) — bare names and :latest trigger unpinned-base because cache keys are not reproducible.
Mistake:Running apt-get update in its own layer.
Fix:Combine update and install in a single RUN; a lone update layer goes stale and raises apt-update-layer.
Mistake:Assuming COPY --from=builder needs a hint to be recognized.
Fix:COPY --from lines already parse as COPY instructions tied to their stage; no finding is emitted for them — the multi-stage hint only appears for single-stage builds with compile commands.
Frequently asked questions
What does this tool do?
It parses your Dockerfile into instructions and named stages, then reports ordered findings — unpinned-base warnings for latest tags, apt-update-layer and apt-cache warnings for apt hygiene, plus dockerignore, run-combine, and multi-stage hints — alongside a layer count, a cache estimate, and an optimized Dockerfile with merged RUN layers.
Why am I seeing apt-update-layer and apt-cache warnings?
apt-update-layer means a RUN calls apt-get update without apt-get install in the same layer, so the package index goes stale; apt-cache means an install layer never removes /var/lib/apt/lists/*. Combine update and install in one RUN ending with rm -rf /var/lib/apt/lists/* — the optimizer's output already applies exactly that fix.
Is my Dockerfile uploaded or stored?
No. Parsing, analysis, and optimization are pure client-side string processing — your Dockerfile never leaves your browser.
When does the multi-stage hint appear?
Only when build-tool RUN commands (npm, pnpm, yarn, go, cargo, mvn, or gradle with build/install/compile) appear in a single-stage file. Files that already define two or more stages — including COPY --from=<stage> lines — never receive it.
Related guides
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.gitattributes Generator
Build .gitattributes rules for line endings, Git LFS, GitHub linguist marks and merge drivers — with a one-line explanation for every rule.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
A/B Test Sample Size Calculator
Compute required sample size per variant and test duration from baseline conversion rate, minimum detectable effect, alpha and power.
ABA Routing Number Validator
Validate 9-digit US ABA routing numbers with 3-7-1 Mod-10 breakdown.