← All insightsCI/CD

Integrating Docker into your CI/CD pipeline

Nir Geier, CodeWizard · 26 September 2026 · 3 min read · Intermediate

Getting Docker into your pipeline is where it starts paying off - automated, repeatable and reviewed. Here is a working integration and the habits that keep it reliable.

A working pipeline snippet

Build and push an image from GitHub Actions using Buildx and layer caching.

yaml
name: build-image
on: { push: { branches: [main] } }
jobs:
  image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v6
        with:
          push: true
          tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

Do this

  • Pin base image tags (or digests) instead of :latest for reproducibility
  • Order layers from least- to most-frequently changed to maximize cache hits
  • Use multi-stage builds to keep runtime images tiny and attack surface small
  • Add a HEALTHCHECK and run as a non-root user

Avoid this

  • Running as root inside the container - always add a non-root USER
  • Fat images from a single-stage build; use multi-stage and slim/alpine bases
  • Baking secrets into layers with COPY or ENV - they stay in the image history
  • No .dockerignore, so node_modules and .git bloat the build context

Want senior help putting Docker to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult