Skip to content
Back to skills

Dockerfile Optimizer

BSecurity

Analyze Dockerfiles for size, build speed, and security — generate

  • 21 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added June 7, 2026
securitypythonnodedockerapisecurity

Works with

  • api

Security analysis

B85/100
  • highPerforms destructive filesystem operations

Pro scans all 2 files and shows the line behind each finding

Scanned June 7, 2026

npx -y skills add modbender/skill-library-mcp --skill dockerfile-optimizer --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dockerfile Optimizer?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Dockerfile Optimizer
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/modbender-dockerfile-optimizer/badge)](https://www.skillsdirectory.com/skills/modbender-dockerfile-optimizer)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: dockerfile-optimizer
description: Analyze Dockerfiles for size, build speed, and security — generate
  optimized versions.
---


# Dockerfile Optimizer

Analyze and optimize Dockerfiles for smaller images, faster builds, and better security.

## Instructions

1. **Read the Dockerfile**: Accept file path or pasted content. Parse all stages.

2. **Check best practices and flag issues**:

   | Check | Issue | Fix |
   |-------|-------|-----|
   | Base image | Uses `:latest` tag | Pin specific version: `node:20-alpine` |
   | Layer count | Multiple separate `RUN` commands | Combine with `&&` |
   | Cache order | Frequently-changing files copied early | Copy dependency files first, then source |
   | User | Runs as root | Add `USER node` or `USER appuser` |
   | COPY vs ADD | Uses `ADD` for plain files | Use `COPY` (ADD only for tar extraction) |
   | Multi-stage | Single stage with build tools in final image | Use multi-stage build |
   | Cleanup | Package cache left in image | Add `rm -rf /var/lib/apt/lists/*` in same RUN |
   | .dockerignore | Missing or incomplete | Generate one |
   | Secrets | Hardcoded tokens/passwords | Use build args or secrets mount |

3. **Size optimization reference**:
   | Base Image | Size | Alternative | Size |
   |-----------|------|-------------|------|
   | `node:20` | ~1 GB | `node:20-alpine` | ~130 MB |
   | `python:3.12` | ~1 GB | `python:3.12-slim` | ~150 MB |
   | `ubuntu:22.04` | ~77 MB | `debian:12-slim` | ~52 MB |
   | Any | varies | `gcr.io/distroless/*` | minimal |

4. **Generate optimized Dockerfile**: Output improved version with comments explaining each change.

5. **Estimate savings**: Report approximate layer reduction and size improvement.

## Security Checks

- 🔴 Hardcoded secrets or ENV with credentials
- 🔴 Running as root without USER instruction
- 🟡 Unnecessary EXPOSE ports
- 🟡 Writable filesystem (consider `--read-only` at runtime)
- 🟡 No HEALTHCHECK instruction

## Edge Cases

- **Multi-stage builds**: Analyze each stage independently
- **Build args**: Ensure `ARG` values don't leak secrets into image layers
- **Platform-specific**: Note if Alpine may cause issues (musl vs glibc)

## Requirements

- No dependencies — static analysis of Dockerfile text
- No API keys needed

Files in this skill

  • README.md773 B
  • SKILL.md2.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in security →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.