一键导入
docker-optimize
Analyze Dockerfile and produce optimized version with multi-stage builds, layer caching, minimal base, and security hardening
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Analyze Dockerfile and produce optimized version with multi-stage builds, layer caching, minimal base, and security hardening
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create Architecture Decision Records using the Michael Nygard template with context, decision, alternatives, and consequences
Generate or validate OpenAPI and AsyncAPI specs from code or requirements with consistent naming, errors, and pagination
Generate CHANGELOG.md from git history in Keep a Changelog format with Added, Changed, Deprecated, Removed, Fixed, and Security categories
Generate CI/CD pipeline config for detected platform with lint, test, build, and deploy stages
Scan dependencies for CVEs, outdated packages, license issues, and unused deps to produce a prioritized remediation list
Guide deployment processes including CI/CD pipeline creation, environment setup, and rollback procedures
| name | docker-optimize |
| description | Analyze Dockerfile and produce optimized version with multi-stage builds, layer caching, minimal base, and security hardening |
| license | MIT |
| compatibility | opencode |
| metadata | {"audience":"developers","workflow":"general"} |
Use this skill when you need to:
Analyze: Read the existing Dockerfile and .dockerignore
Optimize base image: Select the smallest viable base
alpine variants for minimal footprintdistroless for production (no shell, no package manager)slim variants as a middle groundlatestImplement multi-stage build: Separate build and runtime
# Build stage
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --production=false
COPY . .
RUN npm run build
# Production stage
FROM node:20-alpine AS production
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
EXPOSE 3000
CMD ["node", "dist/index.js"]
Maximize layer caching: Order instructions by change frequency
.dockerignore to exclude unnecessary filesSecurity hardening: Apply container security best practices
HEALTHCHECK instructionCOPY instead of ADD unless tar extraction is neededValidate: Verify the optimized image
latest tag for base imageADD when COPY suffices.dockerignoreENV or ARG instructionsRUN commands that should be combined| Metric | Goal |
|---|---|
| Image size | Reduce by 50%+ from naive build |
| Build time (cached) | Under 30 seconds for source-only changes |
| Security | No critical/high CVEs in base image |
| Layers | Minimize total layer count |
FROM eclipse-temurin:21-jdk-alpine AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -DskipTests
FROM eclipse-temurin:21-jre-alpine
COPY --from=build /app/target/*.jar app.jar
USER 1001
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
FROM golang:1.22-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /server .
FROM gcr.io/distroless/static
COPY --from=build /server /server
USER nonroot
EXPOSE 8080
ENTRYPOINT ["/server"]
RUN commands to reduce layers and clean up in the same layer.dockerignore that excludes .git, node_modules, and build artifacts