wrsmith108

JSON output for programmatic use

0
0
# Install this skill:
npx skills add wrsmith108/claude-skill-docker-optimizer

Or install specific skill: npx add-skill https://github.com/wrsmith108/claude-skill-docker-optimizer

# Description

Claude Code skill for analyzing and optimizing Dockerfiles for faster builds and smaller images

# SKILL.md

Docker Optimizer Skill

Analyzes and optimizes Dockerfiles for faster builds and smaller images.

Trigger Phrases

  • "slow docker build"
  • "optimize Dockerfile"
  • "layer caching"
  • "reduce image size"
  • "docker build taking too long"
  • "docker optimization"
  • "dockerfile performance"
  • "image too large"

Capabilities

  1. Layer Order Analysis - Detects inefficient layer ordering that breaks cache
  2. Multi-stage Build Detection - Identifies opportunities for multi-stage builds
  3. Base Image Optimization - Recommends slim/alpine variants
  4. Production Dependencies - Ensures dev dependencies are excluded
  5. Package Manager Cleanup - Verifies apt-get/apk cleanup
  6. Build Time Estimation - Estimates time savings from optimizations
  7. Image Size Estimation - Estimates size reduction from optimizations

Usage

Command Line

# Analyze Dockerfile in current directory
npx tsx scripts/index.ts

# Analyze specific Dockerfile
npx tsx scripts/index.ts /path/to/Dockerfile

# JSON output for programmatic use
npx tsx scripts/index.ts --json

Optimization Checks

Check Description Impact
Layer order COPY source after npm install High
Multi-stage build Separate build and runtime stages High
Slim base image Use node:X-slim or alpine Medium
Production deps --production flag on npm ci Medium
Package cleanup apt-get clean after install Medium
.dockerignore Exclude node_modules, .git Medium
WORKDIR usage Explicit WORKDIR instead of cd Low
Non-root user Run as non-root for security Low

Requirements

  • Node.js 18+
  • tsx (for TypeScript execution)

# README.md

Docker Optimizer

A Claude Code skill for analyzing and optimizing Dockerfiles for faster builds and smaller images.

Installation

As a Claude Code Skill

# Clone to your Claude skills directory
git clone https://github.com/wrsmith108/claude-skill-docker-optimizer.git ~/.claude/skills/docker-optimizer

Standalone Usage

npx tsx ~/.claude/skills/docker-optimizer/scripts/index.ts [dockerfile-path] [options]

Trigger Phrases

This skill activates when you mention:
- "slow docker build"
- "optimize Dockerfile"
- "layer caching"
- "reduce image size"
- "docker build taking too long"
- "docker optimization"
- "dockerfile performance"
- "image too large"

Capabilities

  1. Layer Order Analysis - Detects inefficient layer ordering that breaks cache
  2. Multi-stage Build Detection - Identifies opportunities for multi-stage builds
  3. Base Image Optimization - Recommends slim/alpine variants
  4. Production Dependencies - Ensures dev dependencies are excluded
  5. Package Manager Cleanup - Verifies apt-get/apk cleanup
  6. Build Time Estimation - Estimates time savings from optimizations
  7. Image Size Estimation - Estimates size reduction from optimizations

Usage

# Analyze Dockerfile in current directory
npx tsx scripts/index.ts

# Analyze specific Dockerfile
npx tsx scripts/index.ts /path/to/Dockerfile

# JSON output for programmatic use
npx tsx scripts/index.ts --json

Optimization Checks

Check Description Impact
Layer order COPY source after npm install High
Multi-stage build Separate build and runtime stages High
Slim base image Use node:X-slim or alpine Medium
Production deps --production flag on npm ci Medium
Package cleanup apt-get clean after install Medium
.dockerignore Exclude node_modules, .git Medium
WORKDIR usage Explicit WORKDIR instead of cd Low
Non-root user Run as non-root for security Low

Output Example

## Dockerfile Analysis

### Issues Found

#### 1. Layer order (Line 5)
**Current:**
```dockerfile
COPY . .
RUN npm install

Fix: Copy package*.json first, then npm install, then copy source

Impact: High - enables npm install layer caching


Summary

Metric Current Optimized
Build time ~5 min ~1 min
Image size ~1.2GB ~400MB
Cache hit rate Low High
## Before/After Example

### Before Optimization

```dockerfile
FROM node:22
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "server.js"]

After Optimization

# Build stage
FROM node:22-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
RUN npm run build

# Production stage
FROM node:22-slim AS production
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
CMD ["node", "dist/server.js"]

Requirements

  • Node.js 18+
  • TypeScript (tsx for execution)

License

MIT

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.