Communitygithub.com

ComeOnOliver/skillshub

审查 Dockerfile,针对最佳实践、安全问题和镜像大小优化(包括多阶段构建和层缓存)提供建议。处理 Docker、容器或部署相关工作时使用。

skillshub 是什么?

这是一个用于分析和优化 Dockerfile 的 AI 技能,覆盖性能、安全性和最佳实践。它通过扫描代码仓库中的 `Dockerfile` 文件,自动检测常见问题,如使用未指定版本的 `latest` 标签、层过多、明文硬编码密码、缺少非 root 用户等,并给出具体的改进建议。该技能支持多阶段构建、层缓存策略、健康检查定义以及 `.dockerignore` 文件生成,帮助显著压缩最终镜像体积。技能内置多个可操作的检查清单和命令行示例(如 `docker scan`、`trivy` 扫描漏洞),适用于 Claude Code、Cursor 等 AI 编码助手。最终能输出一个优化后的 Dockerfile 版本,包含最佳实践和安全性改进。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/crazydubya/docker-optimizer

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Docker Optimizer

分析和优化 Dockerfile 的性能、安全性和最佳实践。

何时使用

  • 用户正在使用 Docker 或容器
  • 需要优化 Dockerfile
  • 容器镜像体积过大
  • 用户提到“Docker”、“容器”、“镜像大小”或“部署”

操作说明

1. 查找 Dockerfile

搜索:Dockerfile、Dockerfile.*、*.dockerfile

2. 检查最佳实践

使用具体的镜像版本标签:

# 不建议
FROM node:latest

# 建议
FROM node:18-alpine

最小化层数:

# 不建议
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git

# 建议
RUN apt-get update && \
    apt-get install -y curl git && \
    rm -rf /var/lib/apt/lists/*

按变更频率排序指令:

# 依赖变更频率低于代码
COPY package*.json ./
RUN npm install
COPY . .

使用 .dockerignore:

node_modules
.git
.env
*.md

3. 多阶段构建

减小最终镜像体积:

# 构建阶段
FROM node:18 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# 运行阶段
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. 安全问题

不要以 root 用户运行:

RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

镜像中禁止存放密钥:

# 不建议:硬编码密钥
ENV API_KEY=secret123

# 建议:使用构建参数或运行时环境变量
ARG BUILD_ENV
ENV NODE_ENV=${BUILD_ENV}

扫描漏洞:

docker scan image:tag
trivy image image:tag

5. 体积优化

使用 Alpine 镜像:

  • node:18-alpine vs node:18(900MB → 170MB)
  • python:3.11-alpine vs python:3.11(900MB → 50MB)

移除不必要的文件:

RUN npm install --production && \
    npm cache clean --force

使用精确的 COPY:

# 不建议:复制所有内容
COPY . .

# 建议:仅复制所需文件
COPY package*.json ./
COPY src ./src

6. 缓存策略

层缓存优化:

# 先安装依赖(若 package.json 未变化,则缓存命中)
COPY package*.json ./
RUN npm install

# 再复制源代码(变化更频繁)
COPY . .
RUN npm run build

7. 健康检查

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD node healthcheck.js

8. 生成优化后的 Dockerfile

提供改进版,包含:

  • 多阶段构建
  • 合适的基镜像
  • 安全改进
  • 层优化
  • 构建缓存
  • .dockerignore 文件

9. 构建命令

高效构建:

# 使用 BuildKit
DOCKER_BUILDKIT=1 docker build -t app:latest .

# 利用注册表缓存进行构建
docker build --cache-from myregistry/app:latest -t app:latest .

10. Dockerfile 检查清单

  • 使用具体的基镜像标签(而非 latest)
  • 若适用则使用多阶段构建
  • 非 root 用户
  • 最小化层数(合并 RUN 命令)
  • 存在 .dockerignore
  • 镜像中无密钥
  • 正确的层排序以利用缓存
  • 使用 Alpine 或 slim 变体
  • 在同一 RUN 层中进行清理
  • 定义了 HEALTHCHECK

安全最佳实践

  • 定期扫描镜像
  • 使用官方基镜像
  • 保持基镜像更新
  • 最小化攻击面(更少的包)
  • 以非 root 用户运行
  • 尽可能使用只读文件系统

支持文件

  • templates/Dockerfile.optimized:优化后的多阶段 Dockerfile 示例
  • templates/.dockerignore:常用的 .dockerignore 模式

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能