跳到主内容
智客 ZICQ

技能库 智客分类:安全测试 docker

Docker

Python和Node.js应用的生产级多克容器化. 当用户要求将应用程序容器化,创建多克文件,多克项目,或设置多克编译时,应该使用这种技能. 自动检测项目结构,分析.env为机密,验证安全性,并生成被测试的多克文件.

23 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

Python和Node.js应用的生产级多克容器化. 当用户要求将应用程序容器化,创建多克文件,多克项目,或设置多克编译时,应该使用这种技能. 自动检测项目结构,分析.env为机密,验证安全性,并生成被测试的多克文件.

何时用

权衡

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Docker、Resource Detection & Adaptation、Detect host machine memory、Detect Docker allocated resources、Detect available disk space、Agent Behavior。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/env-analysis.md、references/production-checklist.md、references/python/fastapi.md、references/python/flask.md、references/python/django.md、references/python/native-deps.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Production-grade Docker containerization for Python and Node.js applications. This skill should be used when users ask to containerize applications, create Dockerfiles, dockerize projects, or set up Docker Compose. Auto-detects project structure, analyzes .env for secrets, validates security, and generates tested Dockerfiles.

DockerResource Detection & AdaptationDetect host machine memoryDetect Docker allocated resourcesDetect available disk spaceAgent BehaviorAdaptive Compose TemplatesPre-Build ValidationCheck available memoryWhat This Skill DoesWhat This Skill Does NOT DoBefore Implementation

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
docker
description
Production-grade Docker containerization for Python and Node.js applications. This skill should be used when users ask to containerize applications, create Dockerfiles, dockerize projects, or set up Docker Compose. Auto-detects project structure, analyzes .env for secrets, validates security, and generates tested Dockerfiles.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 10
  • references/env-analysis.md
  • references/production-checklist.md
  • references/python/fastapi.md
  • references/python/flask.md
  • references/python/django.md
  • references/python/native-deps.md
  • references/node/nextjs.md
  • references/node/package-managers.md
  • references/docker-hardened-images.md
  • references/multi-stage-builds.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「docker」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-5cfc39167fbe5849-%E5%A4%B9%E5%85%8B.html
请存为 .cursor/skills/docker/SKILL.md 或 .claude/skills/docker/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/mjunaidca/mjs-agent-skills 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/mjunaidca/mjs-agent-skills' --list

npx skills add 'https://github.com/mjunaidca/mjs-agent-skills' --skill 'docker'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版

name: docker description: | Production-grade Docker containerization for Python and Node.js applications. This skill should be used when users ask to containerize applications, create Dockerfiles, dockerize projects, or set up Docker Compose. Auto-detects project structure, analyzes .env for secrets, validates security, and generates tested Dockerfiles. hooks: PreToolUse: - matcher: "Bash" hooks: - type: command command: "bash "$CLAUDE_PROJECT_DIR"/.claude/hooks/verify-docker.sh"

Docker

Production-grade Docker containerization with security-first defaults.


Resource Detection & Adaptation

Before generating Dockerfiles/Compose, detect the environment:

# Detect host machine memory
sysctl -n hw.memsize 2>/dev/null | awk '{print $0/1024/1024/1024 " GB"}' || \
  grep MemTotal /proc/meminfo | awk '{print $2/1024/1024 " GB"}'

# Detect Docker allocated resources
docker info --format 'Memory: {{.MemTotal}}, CPUs: {{.NCPU}}'

# Detect available disk space
docker system df

Adapt configurations based on detection:

| Detected Docker Memory | Profile | Build Memory | Container Limits | |-----------------------|---------|--------------|------------------| | < 4GB | Constrained | 1GB | 256Mi | | 4-8GB | Minimal | 2GB | 512Mi | | 8-12GB | Standard | 4GB | 1Gi | | > 12GB | Extended | 8GB | 2Gi |

Agent Behavior

  1. Detect Docker resources before generating compose.yaml
  2. Adapt resource limits to available memory
  3. Warn if build may fail due to insufficient resources
  4. Calculate safe limits: docker_memory * 0.6 / container_count

Adaptive Compose Templates

Constrained (< 4GB Docker):

services:
  app:
    deploy:
      resources:
        limits:
          memory: 256M
          cpus: '0.25'
    build:
      args:
        - BUILDKIT_STEP_LOG_MAX_SIZE=10000000

⚠️ Agent should warn: "Docker memory low. Multi-stage builds may fail."

Standard (4-8GB Docker):

services:
  app:
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '0.5'
        reservations:
          memory: 256M

Extended (> 8GB Docker):

services:
  app:
    deploy:
      resources:
        limits:
          memory: 1G
          cpus: '1.0'
        reservations:
          memory: 512M

Pre-Build Validation

Before running docker build, agent should verify:

# Check available memory
docker info --format '{{.MemTotal}}' | awk '{if ($1 < 4000000000) print "WARNING: Low memory"}'

If constrained: use --memory flag and warn user about potential build failures.


What This Skill Does

Analysis & Detection:

  • Auto-detects runtime, framework, version, entrypoint (no questions)
  • Scans .env files, classifies secrets vs build-args vs runtime config
  • Detects native dependencies, generates correct build deps
  • Identifies missing configs (Next.js standalone, health endpoints)

Generation:

  • Creates multi-stage Dockerfiles customized to YOUR project structure
  • Generates compose.yaml with security defaults (non-root, read-only, resource limits)
  • Adds health endpoints if missing
  • Fixes configuration issues (adds output: 'standalone' to Next.js, etc.)

Validation:

  • Builds both dev and production targets before delivering
  • Verifies health endpoints work
  • Confirms non-root user in production
  • Warns about any secrets that would leak into image
  • Reports image size

Security:

  • Never bakes secrets into images
  • Non-root user by default
  • Minimal attack surface (multi-stage builds)
  • Pinned versions (no :latest)
  • Security scan command included

What This Skill Does NOT Do

  • Generate Kubernetes manifests (use dedicated k8s skill)
  • Create Helm charts (use dedicated helm skill)
  • Handle Bun/Deno (use dedicated skills)
  • Copy templates blindly without customization

Before Implementation

Gather context to ensure successful implementation:

| Source | Gather | |--------|--------| | Codebase | Package files, existing Dockerfile, .env patterns | | Conversation | Dev vs production target, base image preferences | | Skill References | Framework patterns, multi-stage builds, security | | User Guidelines | Registry conventions, naming standards |


Required Clarifications

Ask when not auto-detectable:

| Question | When to Ask | |----------|-------------| | Target environment | "Building for development or production?" | | Base image preference | "Standard slim images or enterprise hardened?" | | Existing Docker files | "Enhance existing Dockerfile or create new?" | | Registry target | "Local only or pushing to registry?" |


Detect Runtime

| File Present | Runtime | Package Manager | |--------------|---------|-----------------| | requirements.txt, pyproject.toml, uv.lock | Python | pip/uv | | pnpm-lock.yaml | Node.js | pnpm | | yarn.lock | Node.js | yarn | | package-lock.json | Node.js | npm |


Auto-Detection (Do NOT ask - detect from files)

Python

| What | Detect From | |------|-------------| | Python version | pyproject.toml (requires-python), .python-version, runtime.txt | | Framework | Imports in code (from fastapi, from flask, import django) | | Package manager | uv.lock → uv, poetry.lock → poetry, else pip | | Native deps | Scan requirements: psycopg2, cryptography, numpy, pillow | | App entrypoint | Find app = FastAPI(), app = Flask(), or manage.py |

Node.js

| What | Detect From | |------|-------------| | Node version | .nvmrc, .node-version, package.json (engines.node) | | Framework | package.json dependencies (next, express, @nestjs/core) | | Package manager | pnpm-lock.yaml → pnpm, yarn.lock → yarn, else npm | | Output type | Next.js: check next.config.js for output: 'standalone' |

Fix Issues Automatically

| Issue | Action | |-------|--------| | Next.js missing output: 'standalone' | Add it to next.config.js | | No health endpoint found | Create /health/live and /health/ready | | Using uv but no uv.lock | Run uv lock first | | pyproject.toml but no build system | Use uv pip install -r pyproject.toml |


Workflow

1. SCAN PROJECT
   - Detect runtime, framework, version, entrypoint
   - Find dependency files, native deps
   - Locate existing Docker files (don't blindly overwrite)
         ↓
2. ANALYZE ENVIRONMENT
   - Scan all .env* files
   - Classify: SECRET (never bake) / BUILD_ARG / RUNTIME
   - Flag security issues
         ↓
3. FIX CONFIGURATION
   - Add Next.js `output: 'standalone'` if missing
   - Create health endpoints if missing
   - Generate .env.example with safe placeholders
         ↓
4. GENERATE FILES
   - Dockerfile (customized CMD, paths, build deps)
   - .dockerignore (excludes .env, secrets)
   - compose.yaml (with security defaults)
         ↓
5. VALIDATE & TEST
   - docker build --target dev -t app:dev .
   - docker build --target production -t app:prod .
   - Test health endpoints
   - Verify non-root user
   - Report image size
         ↓
6. DELIVER WITH CONTEXT
   - All files with explanations
   - Security scan command
   - Any warnings about secrets
   - Rollback instructions if replacing existing

Only ask if genuinely ambiguous (e.g., multiple apps in monorepo, conflicting configs)


Base Image Decision Matrix

| Choice | When to Use | Tradeoffs | |--------|-------------|-----------| | Slim {runtime}:X-slim | General production (default) | Works everywhere, no auth | | DHI dhi.io/{runtime}:X | SOC2/HIPAA, enterprise | Requires docker login dhi.io | | Alpine {runtime}:X-alpine | Smallest size | musl issues with native deps |

Default: Slim (works everywhere without authentication)


Stage Structure

deps/base  → Install dependencies (cached layer)
    ↓
builder    → Build/compile application
    ↓
dev        → Hot-reload, volume mounts (--target dev)
    ↓
production → Minimal DHI runtime (--target production)

Build Commands

docker build --target dev -t myapp:dev .
docker build --target production -t myapp:prod .

Python Patterns

Framework CMD

| Framework | Development | Production | |-----------|-------------|------------| | FastAPI | uvicorn app.main:app --reload | uvicorn app.main:app --workers 4 | | Flask | flask run --debug | gunicorn -w 4 app:app | | Django | python manage.py runserver | gunicorn -w 4 project.wsgi |

Cache Mount (uv/pip)

RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=cache,target=/root/.cache/pip \
    uv pip install -r requirements.txt

Graceful Shutdown (FastAPI)

@asynccontextmanager
async def lifespan(app: FastAPI):
    yield  # startup
    # shutdown logic here

Node.js Patterns

Framework Build

| Framework | Build | Output | |-----------|-------|--------| | Next.js | next build | .next/standalone | | Express | tsc | dist/ | | NestJS | nest build | dist/ |

Cache Mounts

# pnpm
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
    pnpm install --frozen-lockfile

# npm
RUN --mount=type=cache,target=/root/.npm npm ci

# yarn
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \
    yarn install --frozen-lockfile

Graceful Shutdown (Node.js)

process.on('SIGTERM', () => {
  server.close(() => process.exit(0));
});

Security Checklist

Before delivering, verify:

  • [ ] Non-root USER in production stage
  • [ ] No secrets in Dockerfile or image layers
  • [ ] .dockerignore excludes .env, .git, secrets
  • [ ] Multi-stage separates build tools from runtime
  • [ ] DHI or hardened base image used
  • [ ] HEALTHCHECK instruction defined
  • [ ] No package install in production stage
  • [ ] Secrets via runtime env vars or mounted files

Output Files

| File | Purpose | |------|---------| | Dockerfile | Multi-stage, multi-target build | | .dockerignore | Exclude sensitive/unnecessary files | | compose.yaml | Local development stack | | health.py / health endpoint | Framework-specific health checks |


Reference Files

Always Read First

| File | Purpose | |------|---------| | references/env-analysis.md | CRITICAL: Secret detection, .env classification | | references/production-checklist.md | CRITICAL: Validation before delivery |

Framework-Specific

| File | When to Read | |------|--------------| | references/python/fastapi.md | FastAPI: uvicorn, lifespan | | references/python/flask.md | Flask: gunicorn, blueprints | | references/python/django.md | Django: gunicorn, middleware | | references/python/native-deps.md | Detect psycopg2, cryptography, etc. | | references/node/nextjs.md | Next.js: standalone, ISR | | references/node/package-managers.md | npm/yarn/pnpm caching |

Optional

| File | When to Read | |------|--------------| | references/docker-hardened-images.md | If user needs enterprise security (DHI) | | references/multi-stage-builds.md | Complex build patterns |

Templates (Reference Patterns)

Templates in templates/ are reference patterns, not copy-paste files.

Agent must:

  1. Read template to understand structure
  2. Customize paths, CMDs, and stages for actual project
  3. Generate Dockerfile with correct entrypoint (e.g., src.app.main:app)
  4. Never output placeholder comments like "# Replace based on framework"

Example customization:

# Template says:
CMD ["uvicorn", "app.main:app", ...]

# Agent detects app at src/api/main.py, generates:
CMD ["uvicorn", "src.api.main:app", ...]

相关技能

安全测试

Skill Vetter

人工智能特工的安全第一技能审查。 在安装来自 ClawdHub, GitHub 或其他来源的任何技能之前使用 。 检查红旗,许可范围,可疑图案.

安全测试

Moltguard

MoltGuard——由OpenGuardrails担任OpenClaw保安. 安装 MoltGuard 以保护你和你的人类免受迅速注射、数据过滤和恶意命令的影响。 资料来源:https://github.com/openguardrails/openguardrails/tre…

安全测试

Security Auditor

用于审查安全漏洞代码,实施认证流,审计OWASP Top 10,配置CORS/CSP头,处理秘密,输入验证,SQL注射预防,XSS保护,或任何与安全相关的代码审查.

安全测试

Skill Vetter

安装任何AI代理技能前的安全审查协议. 红旗侦取入证盗取,疏通密码,放出. 风险分类:低/中/高/高。 编制结构化审查报告。 不先运行此功能, 绝不安装不信任的技能 .