
Docker Cicd
- 10 installs
- 2 repo stars
- Updated July 29, 2026
- full-statck-skills/docker-skills
Automate Docker image builds, pushes, and deployments in GitHub Actions or Jenkins pipelines with buildx multi-platform builds and layer caching.
About
Guides integrating Docker into CI/CD pipelines using GitHub Actions, Jenkins, buildx multi-platform builds, and image caching. A developer uses it to automate Docker image build, push, and deploy from a pipeline.
- GitHub Actions build-push-action with buildx multi-platform builds and GHA layer caching
- Jenkins pipeline, Docker Build Cloud, and rolling / blue-green deployment patterns
Docker Cicd by the numbers
- 10 all-time installs (skills.sh)
- Ranked #1,007 of 1,435 DevOps & CI/CD skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/docker-skills --skill docker-cicdAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 10 |
|---|---|
| repo stars | ★ 2 |
| Last updated | July 29, 2026 |
| Repository | full-statck-skills/docker-skills ↗ |
What it does
Automate Docker image builds, pushes, and deployments in GitHub Actions or Jenkins pipelines with buildx multi-platform builds and layer caching.
Files
Docker CI/CD — 持续集成与持续部署
Guidance for integrating Docker into automated build, test, and deployment pipelines.
When to Use
ALWAYS use this skill when the user mentions:
- "docker CI", "docker CD", "CI/CD pipeline"
- "GitHub Actions docker", "Jenkins docker"
- "buildx", "multi-platform build", "多平台构建"
- "Docker Build Cloud"
- "镜像构建流水线"
GitHub Actions
Build & Push Pipeline
name: Build and Push
on:
push:
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: user/app:${{ github.ref_name }},user/app:latest
cache-from: type=gha
cache-to: type=gha,mode=maxMulti-Platform Build
- name: Build and push multi-platform
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: user/app:latestJenkins Pipeline
pipeline {
agent any
environment {
DOCKER_IMAGE = 'myapp'
DOCKER_TAG = "${env.BUILD_NUMBER}"
}
stages {
stage('Build') {
steps {
sh "docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} ."
}
}
stage('Test') {
steps {
sh "docker run --rm ${DOCKER_IMAGE}:${DOCKER_TAG} npm test"
}
}
stage('Push') {
steps {
withDockerRegistry([credentialsId: 'docker-hub']) {
sh "docker push ${DOCKER_IMAGE}:${DOCKER_TAG}"
}
}
}
}
}Layer Caching in CI
# Pull previous image for layer cache
docker pull $IMAGE:latest || true
docker build \
--cache-from $IMAGE:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-t $IMAGE:$TAG .Workflow — 推荐 CI/CD 流程
Step 1: 配置 CI 环境: docker/login-action + docker/setup-buildx-action Step 2: 构建镜像: docker/build-push-action + registry 缓存加速 Step 3: 安全扫描: docker/scout-action 扫描 CVE + 策略门禁 Step 4: 推送仓库: 多标签(semver + sha + latest)推送到 ghcr.io/Docker Hub Step 5: 部署: ArgoCD/Flux 监听仓库变更自动部署
Gotchas — Common Pitfalls
- CI cache miss: Without
--cache-from, every CI build starts from scratch. → Recovery:docker pull myapp:latest || truebefore build; use--cache-from type=ghain GitHub Actions. - Build secrets in CI logs: Never
echoor print secrets. Use buildx--secretor CI secrets masking. → Recovery:docker buildx build --secret id=npmrc,src=$HOME/.npmrc; check CI secrets are masked in logs. - Disk space in CI: Multi-stage builds can consume CI disk. → Recovery:
docker system prune -afbetween builds; monitor withdocker system df. - Multi-platform emulation slow: QEMU emulation for ARM on AMD is slow (~10x). → Recovery: Use native ARM runners (e.g., GitHub Actions ARM64 runners) or Docker Build Cloud for multi-platform.
Boundary — 能力边界(适用与不适用场景)
| 分类 | 场景 | 说明 |
|---|---|---|
| ✅ 能做 | GitHub Actions Docker 集成 | docker/build-push-action + QEMU + multi-arch |
| ✅ 能做 | Jenkins Pipeline Docker | Docker agent + build/push/scan |
| ✅ 能做 | 多平台 CI 构建 | buildx + QEMU + 多架构 manifest |
| ⚠️ 需条件 | Docker Build Cloud 加速 | 需付费订阅 |
| ⚠️ 需条件 | 非 GitHub/Jenkins CI | 参考通用模式适配 |
| ❌ 超范围 | Dockerfile 编写 | 使用 docker-dockerfile |
| ❌ 超范围 | K8s CD(ArgoCD/Flux) | K8s 部署技能 |
| ❌ 超范围 | CI 平台搭建(Jenkins 安装) | DevOps 基础设施 |
When NOT to Use
| ❌ Skip | ✅ Use Instead |
|---|---|
| Writing Dockerfile | docker-build |
| Security scanning | docker-security / docker-scout |
| Production deployment | docker-production |
| Registry management | docker-hub |
Security & Stability
- Never hardcode registry credentials in CI configs. Use CI secrets manager (GitHub Secrets, Jenkins Credentials).
- Use OIDC (OpenID Connect) for cloud registry auth instead of long-lived credentials.
- Scan images with Docker Scout before pushing to production registry.
- Tag images with SHA digest for audit trails:
image:sha-${GITHUB_SHA::7}. - Rotate registry tokens regularly. Never use personal access tokens for CI.
📚 官方文档参考
| 文档 | 地址 |
|---|---|
| Docker Build CI | https://docs.docker.com/build/ci/ |
| Docker Build Cloud | https://docs.docker.com/build-cloud/ |
| GitHub Actions Docker | https://docs.docker.com/build/ci/github-actions/ |
| Docker Scout CI | https://docs.docker.com/scout/policy/ci/ |
| Buildx CI 集成 | https://docs.docker.com/build/ci/github-actions/build-push-action/ |
🧭 Docker Skills Journey
📍 You are here: `docker-cicd` — CI/CD 自动化
← Previous: docker-build | → Next: docker-production
FAQ
Q1: 如何快速上手此技能? A: 参考上方的快速开始章节,按步骤操作即可。
Q2: 遇到版本不兼容问题怎么办? A: 检查依赖版本,使用 lock 文件锁定,参考常见陷阱章节。
Q3: 如何在生产环境使用? A: 参考最佳实践章节,确保配置正确,做好监控和日志。
Q4: 性能如何优化? A: 参考性能优化相关文档,使用缓存、索引等手段。
Q5: 如何贡献或反馈问题? A: 在 GitHub 仓库提交 Issue 或 Pull Request。
Q6: 是否支持中文? A: 支持中文文档和中文注释,详见国内适配章节。
GitHub Actions — Build, Scan, Push
name: Build and Deploy
on:
push:
branches: [main]
tags: ['v*']
env:
IMAGE_NAME: myapp
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=
- name: Build and Push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=maxJenkins Pipeline with Docker
pipeline {
agent any
environment {
REGISTRY = 'docker.io/myorg'
IMAGE_NAME = 'myapp'
}
stages {
stage('Checkout') {
steps { checkout scm }
}
stage('Build') {
steps {
script {
docker.build("${IMAGE_NAME}:${BUILD_NUMBER}")
}
}
}
stage('Test') {
steps {
script {
docker.image("${IMAGE_NAME}:${BUILD_NUMBER}").inside {
sh 'npm test'
}
}
}
}
stage('Push') {
steps {
script {
docker.withRegistry("https://${REGISTRY}", 'docker-hub-cred') {
docker.image("${IMAGE_NAME}:${BUILD_NUMBER}").push()
docker.image("${IMAGE_NAME}:${BUILD_NUMBER}").push('latest')
}
}
}
}
}
post {
always { cleanWs() }
}
}CI 多架构构建:GitHub Actions + buildx + QEMU
.github/workflows/multi-arch.yml
name: Multi-Arch Build and Push
on:
push:
tags: ['v*']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64,arm,s390x
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=sha,format=short
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Verify manifest
run: |
docker buildx imagetools inspect \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}仅构建不推送(PR 验证)
- name: Build (PR check)
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: false
cache-from: type=gha
Buildx Multi-Platform Build
# Create builder with multi-platform support
docker buildx create --name multiarch --use
docker buildx inspect --bootstrap
# Build for multiple platforms
docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push .
# Check platform support
docker buildx imagetools inspect myapp:latest
# GitHub Actions example: add platforms to build-push-action
# platforms: linux/amd64,linux/arm64Docker Build Cloud CI 集成
概述
将构建卸载到云端 BuildKit 集群,CI Runner 仅发送构建上下文。
前置步骤
# 登录 Docker(需付费订阅)
docker login
# 创建 Cloud Builder
docker buildx create \
--name cloud-builder \
--driver cloud \
--use
# 验证
docker buildx lsGitHub Actions 集成
- name: Set up Docker Buildx with Cloud
uses: docker/setup-buildx-action@v3
with:
driver: cloud
endpoint: myorg/cloud-builder # Build Cloud endpoint
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: myorg/myapp:latest
cache-from: type=registry,ref=myorg/myapp:buildcache
cache-to: type=registry,ref=myorg/myapp:buildcache,mode=maxJenkins Pipeline
pipeline {
agent any
environment {
DOCKER_BUILDKIT = '1'
}
stages {
stage('Build') {
steps {
sh '''
docker buildx build \
--builder cloud-builder \
--platform linux/amd64,linux/arm64 \
--tag myorg/myapp:${BUILD_NUMBER} \
--push .
'''
}
}
}
}共享缓存
团队内所有成员共享 Build Cloud 缓存,无需额外配置:
开发者 A 构建 → 缓存写入 Cloud
开发者 B 构建 → 命中 A 的缓存(层 hash 匹配)
CI 构建 → 命中团队缓存与本地构建对比
| 指标 | 本地 | Build Cloud |
|---|---|---|
| 首次构建 (多平台) | ~12 min | ~6 min |
| 二次构建(缓存命中) | ~2 min | ~1 min |
| CI Runner 规格 | 高性能(4c8g+) | 低配(2c4g 即可) |
| 团队缓存共享 | ❌ | ✅ |