Dockerfile Layer Optimizer
Analyze layers, cache behavior, and multi-stage Docker builds locally
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.
.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.
AI Function Calling Schema Generator
Generate function calling JSON schemas from TypeScript interfaces
Algorithm Arena & Data Structure Visualizer
Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.
Ansible Playbook Generator
Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML