跳到主内容
智客 ZICQ

技能库 智客分类:运维与云 docker-deployment

Docker Deployment

将Node.js应用程序与多克整合和部署,包括多级建筑、多克编译和生产优化

531 安装量

官方网址:skills.sh

技能介绍

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

做什么

将Node.js应用程序与多克整合和部署,包括多级建筑、多克编译和生产优化

何时用

当 :

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Docker Deployment Skill、Quick Start、Core Concepts、Basic Dockerfile、Multi-Stage Build (Optimized)、Build stage。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

Containerize and deploy Node.js applications with Docker including multi-stage builds, Docker Compose, and production optimization

Docker Deployment SkillQuick StartCore ConceptsBasic DockerfileMulti-Stage Build (Optimized)Build stageProduction stageCopy from builderCreate non-root userLearning PathBeginner (1-2 weeks)Intermediate (3-4 weeks)

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
docker-deployment
description
Containerize and deploy Node.js applications with Docker including multi-stage builds, Docker Compose, and production optimization
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

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

安装这个技能

Skills CLI ↗

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

交给 Agent 安装

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

把 Agent Skill「docker-deployment」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-0abf11e533bcabd6-Docker-%E9%83%A8%E7%BD%B2.html
请存为 .cursor/skills/docker-deployment/SKILL.md 或 .claude/skills/docker-deployment/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

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

npx skills add 'https://github.com/pluginagentmarketplace/custom-plugin-nodejs' --list

npx skills add 'https://github.com/pluginagentmarketplace/custom-plugin-nodejs' --skill 'docker-deployment'

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

阅读排版

name: docker-deployment description: Containerize and deploy Node.js applications with Docker including multi-stage builds, Docker Compose, and production optimization sasmp_version: "1.3.0" bonded_agent: 01-nodejs-fundamentals bond_type: PRIMARY_BOND

Docker Deployment Skill

Master containerizing and deploying Node.js applications with Docker for consistent, portable deployments.

Quick Start

Dockerize Node.js app in 3 steps:

  1. Create Dockerfile - Define container image
  2. Build Image - docker build -t myapp .
  3. Run Container - docker run -p 3000:3000 myapp

Core Concepts

Basic Dockerfile

FROM node:18-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

EXPOSE 3000

CMD ["node", "src/index.js"]

Multi-Stage Build (Optimized)

# Build stage
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

# Production stage
FROM node:18-alpine

WORKDIR /app

# Copy from builder
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app .

# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001

USER nodejs

EXPOSE 3000

HEALTHCHECK --interval=30s --timeout=3s \
  CMD node healthcheck.js || exit 1

CMD ["node", "src/index.js"]

Learning Path

Beginner (1-2 weeks)

  • ✅ Understand Docker basics
  • ✅ Create simple Dockerfile
  • ✅ Build and run containers
  • ✅ Manage volumes and networks

Intermediate (3-4 weeks)

  • ✅ Multi-stage builds
  • ✅ Docker Compose
  • ✅ Environment variables
  • ✅ Health checks

Advanced (5-6 weeks)

  • ✅ Image optimization
  • ✅ Production best practices
  • ✅ Container orchestration
  • ✅ CI/CD integration

Docker Compose

# docker-compose.yml
version: '3.8'

services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgresql://db:5432/myapp
      - REDIS_URL=redis://redis:6379
    depends_on:
      - db
      - redis
    restart: unless-stopped

  db:
    image: postgres:15-alpine
    environment:
      - POSTGRES_USER=myapp
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=myapp
    volumes:
      - postgres-data:/var/lib/postgresql/data

  redis:
    image: redis:7-alpine
    volumes:
      - redis-data:/data

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - app

volumes:
  postgres-data:
  redis-data:

Docker Compose Commands

# Start services
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

# Rebuild images
docker-compose up -d --build

# Scale services
docker-compose up -d --scale app=3

.dockerignore

node_modules
npm-debug.log
.git
.gitignore
.env
.env.local
.vscode
*.md
tests
coverage
.github
Dockerfile
docker-compose.yml

Docker Commands

# Build image
docker build -t myapp:latest .

# Run container
docker run -d -p 3000:3000 --name myapp myapp:latest

# View logs
docker logs -f myapp

# Enter container
docker exec -it myapp sh

# Stop container
docker stop myapp

# Remove container
docker rm myapp

# List images
docker images

# Remove image
docker rmi myapp:latest

# Prune unused resources
docker system prune -a

Environment Variables

# In Dockerfile
ENV NODE_ENV=production
ENV PORT=3000

# Or in docker-compose.yml
environment:
  - NODE_ENV=production
  - PORT=3000

# Or from .env file
env_file:
  - .env.production

Volumes for Persistence

services:
  app:
    volumes:
      - ./logs:/app/logs              # Bind mount
      - node_modules:/app/node_modules # Named volume

volumes:
  node_modules:

Health Checks

# In Dockerfile
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
  CMD node healthcheck.js || exit 1
// healthcheck.js
const http = require('http');

const options = {
  host: 'localhost',
  port: 3000,
  path: '/health',
  timeout: 2000
};

const request = http.request(options, (res) => {
  console.log(`STATUS: ${res.statusCode}`);
  process.exit(res.statusCode === 200 ? 0 : 1);
});

request.on('error', (err) => {
  console.log('ERROR:', err);
  process.exit(1);
});

request.end();

Image Optimization

# Use Alpine (smaller base image)
FROM node:18-alpine  # 180MB vs node:18 (1GB)

# Multi-stage build (remove build dependencies)
# Use .dockerignore (exclude unnecessary files)
# npm ci instead of npm install (faster, deterministic)
# Only production dependencies
RUN npm ci --only=production

# Combine RUN commands (fewer layers)
RUN apk add --no-cache git && \
    npm ci && \
    apk del git

Production Best Practices

FROM node:18-alpine

# Don't run as root
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001

WORKDIR /app

COPY --chown=nodejs:nodejs package*.json ./
RUN npm ci --only=production

COPY --chown=nodejs:nodejs . .

USER nodejs

# Health check
HEALTHCHECK CMD node healthcheck.js || exit 1

# Use node instead of npm start (better signal handling)
CMD ["node", "src/index.js"]

Docker Hub Deployment

# Login
docker login

# Tag image
docker tag myapp:latest username/myapp:1.0.0
docker tag myapp:latest username/myapp:latest

# Push to Docker Hub
docker push username/myapp:1.0.0
docker push username/myapp:latest

# Pull from Docker Hub
docker pull username/myapp:latest

CI/CD with GitHub Actions

name: Docker Build & Deploy

on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: docker/setup-buildx-action@v2

      - uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - uses: docker/build-push-action@v4
        with:
          push: true
          tags: username/myapp:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

Common Issues & Solutions

Node modules caching

# Cache node_modules layer
COPY package*.json ./
RUN npm ci
COPY . .  # This doesn't rebuild node_modules

Signal handling

# Use node directly (not npm)
CMD ["node", "src/index.js"]

# In app: Handle SIGTERM
process.on('SIGTERM', () => {
  server.close(() => process.exit(0));
});

When to Use

Use Docker deployment when:

  • Need consistent environments (dev, staging, prod)
  • Deploying microservices
  • Want easy scaling and orchestration
  • Using cloud platforms (AWS, GCP, Azure)
  • Implementing CI/CD pipelines

Related Skills

  • Express REST API (containerize APIs)
  • Database Integration (multi-container setup)
  • Testing & Debugging (test in containers)
  • Performance Optimization (optimize images)

Resources

相关技能

运维与云

Docker Essentials

用于容器管理,图像操作,调试的基本道克命令和工作流程.

运维与云

Find Skills

从开放的代理技能生态系统中发现并安装技能. 使用时:(1)用户问"我如何做X",X可能拥有现有技能,(2)用户说"为X找到技能"或"是否为X有技能",(3)用户问"你能否做X",X是专门能力,(4)用户想扩展代理能力,(5)用户想搜索工具,模板,或工作流程,(6)用户提到他们希望…

运维与云

Microsoft Foundry

构建,部署,评价,优化,微调,管理微软创始代理,模型,资源最终结束. 用法:铸造、azd ai代理、azd 提供/部署、托管代理脚手架/开发/运行/部署/拖放、即时代理创建、创建代理、更新代理、添加代理工具、援引代理、代理.yaml、评估代理、批量活化、连续活化、持续监测、代理C…

运维与云

Azure Deploy

执行已有.azure/部署计划.md和基础设施文件的ALREADY-PREPARED应用程序的Azure部署。 当用户向 CREATE 请求新应用程序时, 请不要使用此技能 。 这种技能运行了 azd上行, azd 部署, trarraform 应用, 和 az 部署命令带有内置…