dockerfile minimizer

    1

    Reduce Docker image size and build times using multi-stage builds and optimized layer caching.

    Free

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    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%)

    ChangeSavingBasis
    Switch to multi-stage build~600 MBestimated: build tools left in builder
    node:20 to node:20-slim~150 MBdocumented base size difference
    npm ci --omit=dev~85 MBestimated 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

    1. Run docker build -t myapp:new . to verify the new image size.
    2. Verify that any native modules (e.g. bcrypt, sharp) still function in the slim base.
    3. Use docker history myapp:new to confirm no secrets were baked into the layers.
    COPY package.json

    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

    1. Analyze inputs Review the Dockerfile, docker history, and project manifests to identify high-leverage savings.
    2. Determine shipping unit Identify the absolute minimum set of files required for the application to run.
    3. Draft optimized stages Create a builder stage for dependencies and a hardened runtime stage for execution.
    4. 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Node.js
    Python
    Git

    Permissions

    Terminal / Shell
    Network Access
    Read Files
    Write Files

    File Scopes

    Dockerfile
    Dockerfile.*
    *.Dockerfile
    .dockerignore
    Listed9 days ago
    Updated7 days ago

    What's inside

    Frequently Asked Questions

    The skill provides a fully optimized multi-stage Dockerfile, a custom-tailored .dockerignore file, and a performance report detailing the estimated reduction in image size and build times.

    Absolutely. The skill replaces heavy default distributions with production-grade alternatives like slim or distroless images and implements non-root user configurations to meet Kubernetes and enterprise security standards.

    Unlike generic AI prompts, this skill uses a specialized logic to handle complex library dependencies, such as identifying when Alpine's musl libc might break Python or Node.js native modules, ensuring your optimized image remains functional.

    This skill is designed to work with any AI agent capable of file processing and text generation, including popular LLM interfaces and developer-focused agentic workflows.

    Yes, the skill is optimized for modern CI/CD workflows and supports BuildKit-specific features like --mount=type=cache to ensure your pipeline runs as fast as possible.

    Simply provide your current Dockerfile and a list of your project's primary languages or frameworks; no complex installation or environment access is required to generate the optimized output.

    New in DevOps & Cloud