docker-optimizerlisted
Install: claude install-skill aiskillstore/marketplace
# Docker Optimizer
Analyzes and optimizes Dockerfiles for performance, security, and best practices.
## When to Use
- User working with Docker or containers
- Dockerfile optimization needed
- Container image too large
- User mentions "Docker", "container", "image size", or "deployment"
## Instructions
### 1. Find Dockerfiles
Search for: `Dockerfile`, `Dockerfile.*`, `*.dockerfile`
### 2. Check Best Practices
**Use specific base image versions:**
```dockerfile
# Bad
FROM node:latest
# Good
FROM node:18-alpine
```
**Minimize layers:**
```dockerfile
# Bad
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git
# Good
RUN apt-get update && \
apt-get install -y curl git && \
rm -rf /var/lib/apt/lists/*
```
**Order instructions by change frequency:**
```dockerfile
# Dependencies change less than code
COPY package*.json ./
RUN npm install
COPY . .
```
**Use .dockerignore:**
```
node_modules
.git
.env
*.md
```
### 3. Multi-Stage Builds
Reduce final image size:
```dockerfile
# Build stage
FROM node:18 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# Production stage
FROM node:18-alpine
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
CMD ["node", "dist/index.js"]
```
### 4. Security Issues
**Don't run as root:**
```dockerfile
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
```
**No secrets in image:**
```dockerfile
# Bad: Hardco