dockerfile-optimizer

Optimize Dockerfiles with multi-stage builds, minimal base images, and caching.

3|Updated Mar 31, 2026
One-click install
npx skills add https://github.com/sunny0826/open-source-skills --skill dockerfile-optimizer-sunny0826
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dockerfile-optimizer
Source: https://github.com/sunny0826/open-source-skills/tree/main/skills/dockerfile-optimizer
Command: npx skills add https://github.com/sunny0826/open-source-skills --skill dockerfile-optimizer-sunny0826

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Dockerfile optimization often suffers from bloated images, slow builds, and security gaps due to outdated practices. This skill helps engineers systematically refactor Dockerfiles to minimize image size, accelerate builds, and harden runtime security.

Core Features & Use Cases

  • Identify and convert to multi-stage builds to separate build tools from runtime.
  • Switch to smaller base images and prune unnecessary dependencies.
  • Consolidate RUN instructions and clean caches to reduce layers and final image size.
  • Implement non-root execution and proper user permissions.
  • Use cases include optimizing legacy Dockerfiles, creating lean production images, and auditing Dockerfiles for performance and security.

Quick Start

Submit a Dockerfile and receive an optimized, multi-stage Dockerfile with explanations.

Frequently Asked Questions about dockerfile-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize a Dockerfile to reduce image size and speed up builds?

Dockerfile optimization reduces image size and speeds up builds by applying multi-stage builds, switching to minimal base images, and consolidating RUN instructions to reduce layers and clean caches for faster, leaner images.

How does multi-stage build improve Docker image security and performance?

Multi-stage builds improve security and performance by separating build tools from the runtime environment, allowing you to use minimal base images and prune unnecessary dependencies, which results in slimmer, faster, and safer Docker images.

What is the best way to audit a legacy Dockerfile for performance and security gaps?

Auditing a legacy Dockerfile involves refactoring it to implement non-root execution and proper user permissions, alongside converting to multi-stage builds to harden runtime security and identify outdated practices causing bloated images.

Can I implement non-root execution and proper user permissions in my Dockerfile?

Yes, you can implement non-root execution and proper user permissions in a Dockerfile to harden runtime security, ensuring the application runs with minimized privileges and reducing potential security vulnerabilities.

Why does my Docker image remain bloated after cleaning apt or apk caches?

Docker images stay bloated if you only clean caches without consolidating RUN instructions or switching to smaller base images, as unused build tools and unnecessary dependencies from outdated practices still remain in the final layers.