
Docker Build Deploy
- 416 installs
- Updated June 24, 2026
- wu529778790/shenzjd-skills
Helps with devops & ci/cd tasks.
About
docker-build-deploy is a Claude Code skill for devops & ci/cd. It helps solo builders move faster with AI-assisted coding.
- docker-build-deploy
- DevOps & CI/CD
- AI-coding skill
Docker Build Deploy by the numbers
- 416 all-time installs (skills.sh)
- +62 installs in the week ending Jul 27, 2026 (Skillselion tracking)
- Ranked #286 of 1,435 DevOps & CI/CD skills by installs in the Skillselion catalog
- Data as of Jul 27, 2026 (Skillselion catalog sync)
npx skills add https://github.com/wu529778790/shenzjd-skills --skill docker-build-deployAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 416 |
|---|---|
| Last updated | June 24, 2026 |
| Repository | wu529778790/shenzjd-skills ↗ |
What it does
Helps with devops & ci/cd tasks.
Files
Docker Build & Deploy
一键生成 Docker 构建 + 推送到 GHCR + 部署到服务器的 GitHub Actions 工作流。
Overview
自动生成完整的 Docker CI/CD 工作流:构建镜像 → 推送到 GHCR → SSH 部署到服务器。包含优化的 Dockerfile(多阶段构建、非 root、健康检查)和 GitHub Actions 工作流模板。
When to Use
- User wants to containerize a project and deploy it
- User needs GitHub Actions to automatically build Docker images
- User mentions Docker, GHCR, container deployment, or CI/CD
- User inputs
/docker-build-deploy - User wants to set up continuous deployment pipeline
- User wants to push images to a container registry
- User wants to automate deployment to a remote server via SSH
- User wants to optimize existing Dockerfile with multi-stage builds
- User wants to add health checks to container deployment
When NOT to Use:
- User only wants to write a Dockerfile
- User deploys with Kubernetes (different workflow - consider
kubectlor Helm) - User doesn't use GitHub Actions (consider GitLab CI, CircleCI, etc.)
- User wants to deploy to AWS ECS/EKS, Google Cloud Run, or Azure Container Instances (different workflows)
Core Pattern
Step 1: 收集信息
交互式询问:port(容器内端口,默认 3000)、host_port(对外暴露端口,默认同 port)、env_file(服务器 env 路径,可选)。
智能检测:有 package.json → Node.js(当前唯一支持的项目类型)。已有 Dockerfile 则跳过生成。
Step 2: 生成 Dockerfile(如需要)
生成优化的 Node.js Dockerfile:多阶段构建、非 root 用户、健康检查。模板见 templates/Dockerfile.nodejs。
Step 3: 生成 Workflow
从 templates/docker-deploy.yml 生成工作流,替换 {{PORT}}(容器端口)、{{HOST_PORT}}(对外端口)和 {{ENV_FILE}} 变量。
build-and-push job: 登录 GHCR → Buildx 构建 → 推送(tag: latest + sha)→ GHA 缓存
deploy job: SSH 连接 → 拉取镜像 → 停旧容器 → 启新容器(支持 env 文件)→ 清理旧镜像
Step 4: 提示配置 Secrets
告知用户需在 GitHub Settings → Secrets 配置:DEPLOY_HOST、DEPLOY_USER、DEPLOY_PASSWORD。
Quick Reference
/docker-build-deploy
/docker-build-deploy --port 8080
/docker-build-deploy --port 8080 --env-file /opt/app/.env| 参数 | 说明 | 默认值 |
|---|---|---|
--port | 容器内应用端口 | 3000 |
--host-port | 服务器对外暴露端口 | 同 --port |
--env-file | 服务器 env 文件路径 | 空 |
Common Mistakes
| 错误 | 正确做法 | 原因 |
|---|---|---|
用 latest 单 tag | 同时打 latest + ${{ github.sha }} | 方便回滚 |
不设置 packages: write 权限 | 声明 permissions: packages: write | GHCR 推送需要 |
| deploy 不检查容器是否存在 | 先 docker stop + docker rm | 避免端口冲突 |
| 不清理旧镜像 | 部署后 docker image prune -f | 磁盘空间 |
| Dockerfile 用 root 运行 | 添加 USER node 或非 root 用户 | 容器安全最佳实践 |
| Secrets 硬编码在 workflow 中 | 使用 ${{ secrets.XXX }} 引用 | 密钥泄露风险 |
| 不设置 Docker BuildKit 缓存 | 配置 cache-from / cache-to using GitHub Actions cache | 每次全量构建太慢 |
| 不处理构建失败的回滚 | 部署后验证健康检查 | 失败部署可能上线错误版本 |
未指定 --platform | 多平台构建时声明 linux/amd64,linux/arm64 | 目标架构不匹配导致运行失败 |
🐳 Docker Build & Deploy
One-click generation of Docker build + push to GHCR + deploy to server GitHub Actions workflows.
Installation
# npx skills (recommended)
npx skills add wu529778790/shenzjd-skills -s docker-build-deploy -y
# Manual (Claude Code)
git clone https://github.com/wu529778790/shenzjd-skills.git
cp -r shenzjd-skills/docker-build-deploy ~/.claude/skills/
# Manual (Cursor)
# Copy SKILL.md content to .cursorrules or .cursor/rules/Usage
/docker-build-deploy
/docker-build-deploy --port 8080
/docker-build-deploy --port 8080 --env-file /opt/app/.env| Parameter | Description | Default |
|---|---|---|
--port | Container exposed port | 3000 |
--env-file | Server env file path | empty |
Generated Files
`.github/workflows/docker-deploy.yml` — Two jobs:
1. build-and-push: Login to GHCR → Buildx build → Push (latest + sha) → GHA cache 2. deploy (main only): SSH → Pull image → Stop old container → Start new container → Cleanup
`Dockerfile` (if needed) — Auto-detects project type:
| Project Type | Detection | Base Image |
|---|---|---|
| Node.js | package.json | node:20-alpine (multi-stage) |
| Go | go.mod | golang:alpine → alpine |
| Python | requirements.txt | python:3.12-slim |
Prerequisites
Configure in GitHub repo Settings → Secrets:
| Secret | Description |
|---|---|
DEPLOY_HOST | Server IP |
DEPLOY_USER | SSH username |
DEPLOY_PASSWORD | SSH password or private key |
Server must have Docker installed and SSH port open.
name: Build and Push Docker Image
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set image name
run: echo "IMAGE_NAME=ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: read
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to server
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
password: ${{ secrets.DEPLOY_PASSWORD }}
script: |
IMAGE="ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]'):latest"
CONTAINER="${{ github.event.repository.name }}"
# 拉取最新镜像
sudo docker pull "$IMAGE"
# 停止并移除旧容器
sudo docker stop "$CONTAINER" || true
sudo docker rm "$CONTAINER" || true
# 构建环境变量参数
ENV_FLAGS=""
ENV_FILE="{{ENV_FILE}}"
if [ -n "$ENV_FILE" ] && [ -f "$ENV_FILE" ]; then
ENV_FLAGS="--env-file $ENV_FILE"
fi
# 启动新容器
sudo docker run -d \
--name "$CONTAINER" \
--restart unless-stopped \
$ENV_FLAGS \
-p {{HOST_PORT}}:{{PORT}} \
"$IMAGE"
# 清理旧镜像
sudo docker image prune -f
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN npm prune --production
# Production stage
FROM node:20-alpine AS production
WORKDIR /app
RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001 -G appgroup
COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
COPY --from=builder --chown=appuser:appgroup /app/package.json ./
USER appuser
EXPOSE {{PORT}}
HEALTHCHECK --interval=30s --timeout=3s CMD wget --no-verbose --tries=1 --spider http://localhost:{{PORT}}/ || exit 1
CMD ["node", "dist/index.js"]