Optimize Docker images and containers for size, build speed, and runtime performance
Optimizes Docker images for size, build speed, and runtime performance. Triggers when reviewing or writing Dockerfiles to apply multi-stage builds, layer caching, and base image selection.
/plugin marketplace add pluginagentmarketplace/custom-plugin-docker/plugin install pluginagentmarketplace-docker-container-assistant@pluginagentmarketplace/custom-plugin-dockerThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/optimization-tips.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyComprehensive optimization techniques for Docker images and containers covering size reduction, build caching, and runtime performance.
Reduce image size, improve build times, and optimize container performance using 2024-2025 industry best practices.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| target | enum | No | all | size/build/runtime/all |
| base_image | string | No | - | Current base image |
| current_size | string | No | - | Current image size |
| Base | Size | Use Case |
|---|---|---|
| scratch | 0 | Static Go/Rust binaries |
| distroless | 2-20MB | Production containers |
| alpine | 5MB | General purpose |
| slim | 80-150MB | When apt packages needed |
| full | 500MB+ | Development only |
# Before: 1.2GB
FROM node:20
# After: 150MB (88% smaller)
FROM node:20-alpine
# Bad: 3 layers, 150MB
RUN apt-get update
RUN apt-get install -y curl
RUN rm -rf /var/lib/apt/lists/*
# Good: 1 layer, 50MB
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# Clean package manager cache
RUN npm cache clean --force
RUN pip cache purge
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Use .dockerignore
# node_modules, .git, *.md, tests/, docs/
# Dependencies first (rarely change)
COPY package*.json ./
RUN npm ci
# Source code last (frequently changes)
COPY . .
RUN npm run build
# syntax=docker/dockerfile:1
FROM node:20-alpine
# Cache npm packages
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Cache pip packages
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
# Parallel stages (BuildKit)
FROM node:20-alpine AS deps
COPY package*.json ./
RUN npm ci
FROM deps AS builder
COPY . .
RUN npm run build
FROM deps AS linter
COPY . .
RUN npm run lint
services:
app:
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
# Set memory limits
docker run --memory=512m --memory-swap=512m app
# CPU limits
docker run --cpus=1.5 app
# I/O limits
docker run --device-read-bps=/dev/sda:1mb app
# Image size analysis
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
# Layer analysis
docker history <image> --format "{{.Size}}\t{{.CreatedBy}}"
# Deep dive analysis
dive <image>
# Build time analysis
DOCKER_BUILDKIT=1 docker build --progress=plain .
| Issue | Cause | Solution |
|---|---|---|
| Large image | No multi-stage | Implement multi-stage |
| Slow builds | Poor layer order | Dependencies before code |
| Cache not working | Context changes | Use .dockerignore |
| OOM at runtime | No limits | Set memory limits |
DOCKER_BUILDKIT=1)dive)Skill("docker-optimization")
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.