- Home
- Skills
- DevOps & Cloud
- dockerfile minimizer
dockerfile minimizer
Reduce Docker image size and build times using multi-stage builds and optimized layer caching.
Free
Works with the AI Agents you already use
dockerfile minimizer
Example session with this skill installed
My Node.js image is 950MB. Here is my Dockerfile. It uses node:20 and runs npm install. Make it smaller and fix the caching so code changes don't trigger a full reinstall.
- Read your context and instructions
- Compiled the dockerfile minimizer
I have analyzed the Dockerfile. The primary bloat comes from the full Debian-based Node image and the inclusion of devDependencies in the final layer.
Before: 950 MB (estimated)
After: 115 MB (estimated)
Saving: ~835 MB (88%)
| Change | Saving | Basis |
|---|---|---|
| Switch to multi-stage build | ~600 MB | estimated: build tools left in builder |
| node:20 to node:20-slim | ~150 MB | documented base size difference |
| npm ci --omit=dev | ~85 MB | estimated devDependency footprint |
New Dockerfile
# syntax=docker/dockerfile=1
FROM node:20-slim AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
RUN groupadd -g 10001 nodeapp && \
useradd -u 10001 -g nodeapp nodeapp
COPY --from=builder --chown=nodeapp:nodeapp /app/dist ./dist
COPY --from=builder --chown=nodeapp:nodeapp /app/node_modules ./node_modules
COPY --from=builder --chown=nodeapp:nodeapp /app/package.json ./package.json
USER 10001
EXPOSE 3000
CMD ["node", "dist/index.js"]
New .dockerignore
.git
node_modules
npm-debug.log
dist
.env
Per-layer explanation
COPY package.json ... : Manifests are copied before source code. This ensures npm ci only reruns if dependencies change. [CM-02]
Multi-stage build : The compiler and cache are discarded. Only the dist and production node_modules are copied to the runtime. [CM-01]
- USER 10001 : Switched to a numeric UID for compatibility with restricted environments. [CM-09]
Next steps
- Run
docker build -t myapp:new .to verify the new image size. - Verify that any native modules (e.g. bcrypt, sharp) still function in the slim base.
- Use
docker history myapp:newto confirm no secrets were baked into the layers.
Connects securely to your tools. The creator never sees your data.
About this skill
Docker images are often bloated, slow to build, and carry unnecessary security risks due to poor layering and build-time leftovers. This skill eliminates image bloat by rewriting Dockerfiles into optimized multi-stage builds with proper caching and minimal runtime footprints.
What it does
- Multi-stage conversion Rewrites single-stage Dockerfiles to separate build tools from runtime artifacts.
- Layer optimization Reorders instructions to maximize cache hits and prevent unnecessary dependency reinstalls.
- Base image selection Replaces heavy distributions with slim, alpine, or distroless alternatives based on stack requirements.
- Context pruning Generates specific .dockerignore files to reduce build context size and protect secrets.
- Security hardening Implements non-root users, numeric UIDs, and proper signal handling for production readiness.
How it works
- Analyze inputs Review the Dockerfile, docker history, and project manifests to identify high-leverage savings.
- Determine shipping unit Identify the absolute minimum set of files required for the application to run.
- Draft optimized stages Create a builder stage for dependencies and a hardened runtime stage for execution.
- Generate report Deliver the new Dockerfile, .dockerignore, and a detailed before-vs-after size breakdown.
Frameworks & tools
Works with Node.js, Python, Go, Rust, and JVM stacks. Supports standard OCI/Docker builds and BuildKit features like secret and cache mounts.
Why this beats prompting it yourself
Generic LLMs often suggest Alpine for Python or Node without warning you about the musl libc performance traps or DNS differences. This skill uses a structured procedure to ensure that size reductions do not break your native dependencies or debugging workflows.
Use cases
- Shrink a 2GB Node.js image down to under 200MB.
- Stop "npm install" from running on every minor code change.
- Remove build-time secrets and SSH keys leaked in image history.
- Migrate legacy root-run containers to non-root for Kubernetes compliance.
Known limitations
Does not support non-OCI builders like Nix or Bazel. All "after" size figures are estimates based on documented base sizes, as the agent has no local Docker daemon to perform actual builds.
Cannot build or run images. Base image sizes are approximations from 2026-11 data. Does not detect CVEs. Requires manual smoke testing after base image changes.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 9 days ago
- Free with an Agensi account
Requires
Permissions
File Scopes