openclaw-skills/docker-expert/SKILL.md
用于 Docker 容器化最佳实践、多阶段构建优化与 Docker Compose 编排。来源:skills.sh 8.7K installs。
npx skillsauth add seaworld008/commonly-used-high-value-skills docker-expertInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
AS 关键字定义多个阶段。在第一阶段进行源码编译、依赖安装;在第二阶段仅拷贝最终产物(如编译后的二进制文件或静态资源)到轻量级基础镜像(如 Alpine 或 Distroless)中。RUN 指令,清理构建过程中的临时文件(如 npm cache clean, apt-get clean)。package.json, go.mod),运行安装命令,最后再拷贝源代码。这能显著提高后续构建速度。alpine, slim 版本,或 Google 的 distroless 镜像以降低攻击面。.git, node_modules, tests, docs),减小上传给 Docker daemon 的上下文体积。depends_on 及其 condition: service_healthy(结合 healthcheck)确保依赖服务就绪后再启动主应用。docker-compose.override.yml 或 env_file 实现不同环境的差异化配置。bridge(默认隔离)、host(无隔离,高性能)、none 及自定义 overlay 网络。bind mounts(挂载主机目录,常用于开发)和 named volumes(由 Docker 管理,常用于生产)。USER 指令切换到非特权用户。docker scan (Snyk), Trivy 或 Clair 检查镜像中的已知 CVE。--cpus, --memory,防止容器资源耗尽攻击(DoS)。--cache-from 提升流水线中的镜像构建速度。docker login, push 流程。# 查看容器资源占用 (CPU, Memory, Network)
docker stats --no-stream
# 进入运行中的容器排查网络
docker exec -it <container_id> /bin/sh -c "ping db_host && nslookup api_service"
# 清理所有未使用的镜像、容器、卷和网络(一键释放磁盘)
docker system prune -af --volumes
# 查看镜像层级与体积详情
docker history <image_name>
# 阶段 1: 构建 (Build)
FROM node:20-alpine AS builder
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN npm install -g pnpm && pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
# 阶段 2: 运行 (Production)
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
# 拷贝构建产物
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
# 创建非 root 用户并切换
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --quiet --tries=1 --spider http://localhost:3000/health || exit 1
CMD ["node", "dist/main.js"]
version: '3.8'
services:
web:
build: .
ports:
- "80:3000"
environment:
- DB_URL=postgres://user:pass@db:5432/mydb
depends_on:
db:
condition: service_healthy
networks:
- frontend
- backend
db:
image: postgres:16-alpine
volumes:
- db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
networks:
- backend
networks:
frontend:
backend:
internal: true # 限制后端网络不可访问外网
volumes:
db_data:
development
Enumerating failure modes via pre-mortem analysis. Systematically identifies failure scenarios for plans, designs, and features, scoring them with RPN/AP. Does not write code.
testing
Orchestrating specialist AI agent teams as a meta-coordinator. Decomposes requests into minimum viable chains, spawns each as an independent session in AUTORUN modes, and drives to final output. Use when a task spans multiple specialist domains, requires parallel agent execution, or needs hub-and-spoke routing across the skill ecosystem.
development
Converting document formats (Markdown/Word/Excel/PDF/HTML). Converts specs from Scribe and reports from Harvest into distributable formats; generates reusable conversion scripts. Use when converting documents, building accessibility-compliant PDFs, or creating Pandoc/LibreOffice pipelines.
testing
Curating cross-agent knowledge and guarding institutional memory. Extracts patterns from agent journals into METAPATTERNS.md, detects knowledge decay, propagates best practices, prevents organizational forgetting. Use when consolidating cross-agent insights, curating memory, or auditing knowledge decay.