Back to skills
SKILL.md
Dockerfile Optimization
ASecurityUse when optimizing Docker builds: layers, cache.
- 2 stars
- 0 votes
- 0 copies
- 6 views
- Added September 10, 2026
Security analysis
93/100- Performs destructive filesystem operations
npx -y skills add LoopyLuci/Skills --skill dockerfile-optimization --agent claude-codeAre you the author of Dockerfile Optimization?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/loopyluci-dockerfile-optimization)---
name: dockerfile-optimization
description: "Use when optimizing Docker builds: layers, cache."
category: docker
tags: [docker, dockerfile, build, optimization, multistage]
---
# Dockerfile Optimization
Optimizing Docker builds for speed, size, and security.
## Multi-stage Build
```dockerfile
FROM golang:1.21 AS builder
WORKDIR /app; COPY go.mod .; RUN go mod download
COPY . .; RUN CGO_ENABLED=0 go build -o server
FROM alpine:3.18
COPY --from=builder /app/server /server
CMD ["/server"]
```
## Layer Caching
```dockerfile
FROM node:20-alpine
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
```
## Combine RUN
```dockerfile
RUN apt-get update && apt-get install -y curl \\
&& rm -rf /var/lib/apt/lists/*
```
## BuildKit
```powershell
$env:DOCKER_BUILDKIT=1
docker build --no-cache --progress=plain -t myapp .
```
## Pitfalls
- **COPY .** before deps invalidates caches
- **apt install** without cleanup bloats image
- **Distroless** has no shell -- use docker debug
Attribution
Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.