Skip to content
Development
Command

/optimize-dockerfile

Optimize an existing Dockerfile for smaller images, faster builds, and better security.

From plugin
rohitg00-claude-code-toolkit
2.8k199 skills138 agents199 commands
$ npx -y skills add rohitg00/awesome-claude-code-toolkit --agent claude-code

Command definition

optimize-dockerfile.md
name: optimize-dockerfile
description: Optimize an existing Dockerfile for smaller images, faster builds, and better security.

Optimize an existing Dockerfile for smaller images, faster builds, and better security.

Steps

1. Read the existing Dockerfile and analyze each instruction. 2. Check for size optimization opportunities:

  • Use Alpine or distroless base images where possible.
  • Combine RUN commands to reduce layers.
  • Remove package manager caches in the same layer as installs.
  • Use multi-stage builds to exclude build tools from the final image.
  • Copy only necessary files, not the entire context.

3. Check for build cache optimization:

  • Order instructions from least to most frequently changing.
  • Copy dependency files before source code.
  • Use `--mount=type=cache` for package manager caches.

4. Check for security best practices:

  • Use specific version tags for base images.
  • Run as non-root user: `USER <non-root>`.
  • Set `HEALTHCHECK` instruction.
  • Do not store secrets in environment variables or build args.
  • Minimize installed packages to reduce attack surface.

5. Apply optimizations and compare before/after image sizes. 6. Verify the optimized image still runs correctly.

Format

Dockerfile Optimization: <path>

Before: <size>MB, <layers> layers
After: <size>MB, <layers> layers
Reduction: <percent>%

Changes:
  1. Switched base from node:20 to node:20-alpine (-600MB)
  2. Combined 5 RUN commands into 2 (-3 layers)
  3. Added multi-stage build, excluded devDependencies (-200MB)
  4. Added non-root USER instruction (security)

Verification: container starts and passes health check

Rules

  • Always test the optimized image before recommending changes.
  • Do not sacrifice build reliability for marginal size gains.
  • Preserve build cache efficiency; do not combine steps that change independently.
  • Keep security fixes separate from optimization changes for clear review.
  • Document why each base image was chosen.
Read more
@rohitg00
Ships withrohitg00-claude-code-toolkit

The most comprehensive toolkit for Claude Code -- 135 agents, 35 curated skills (+400,000 via SkillKit), 42 commands, 176+ plugins, 20 hooks, 15 rules, 7 templates, 15 MCP configs, 26 companion apps, 53 ecosystem entries, and more.

2.8k40 skills138 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
2.8k
Star history of rohitg00/awesome-claude-code-toolkit on GitHub, a chart by star-history.com

Other commands on rohitg00-claude-code-toolkit.

More commands from other plugins.

build
Auto-invoked

build

Command

Implement tasks incrementally — build, test, verify, commit. Add "auto" to run the whole plan in one approved pass.

@addyosmani@addyosmaniInstall Command