Skip to content
Back to skills

Dockerfile Optimization

ASecurity

Use when optimizing Docker builds: layers, cache.

  • 2 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 10, 2026
ai-agentsgoshellnodedockersecurity

Security analysis

A93/100
  • highPerforms destructive filesystem operations

Pro shows the line behind each finding and how to fix it

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill dockerfile-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dockerfile Optimization?

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

Security grade badge for Dockerfile Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-dockerfile-optimization/badge)](https://www.skillsdirectory.com/skills/loopyluci-dockerfile-optimization)

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-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

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

Comments

Loading comments…

Newsletter

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