✦ For everyone, free.

Practical knowledge for real and everyday life

Home

13.1.1.2 CI Docker Build Step

A focused guide to CI Docker Build Step, connecting core concepts with practical Docker and container operations.

The CI Docker build step actually constructs the application's container image as part of the pipeline, typically benefiting from build caching and other optimizations to keep this potentially time-consuming step reasonably fast across repeated pipeline runs.

A Basic CI Build Step

The most straightforward form simply runs docker build as a pipeline step.

- run: docker build -t myapp:${{ github.sha }} .
Leveraging Build Caching to Speed Up Repeated CI Builds

Without specific configuration, each CI run might start without any of Docker's layer cache from previous runs, since CI runners are often ephemeral — explicitly configuring cache import and export addresses this.

- uses: docker/build-push-action@v5
  with:
    cache-from: type=registry,ref=myapp:buildcache
    cache-to: type=registry,ref=myapp:buildcache,mode=max

This pulls a previously cached set of layers from the registry before building, and pushes an updated cache after, allowing subsequent CI runs to benefit from caching despite running on otherwise fresh, ephemeral runners.

Using BuildKit for More Advanced CI Build Features

Modern CI build steps commonly use BuildKit directly (often through a dedicated build action), unlocking features like more sophisticated caching and multi-platform builds.

- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
  with:
    platforms: linux/amd64,linux/arm64
Why Build Step Performance Matters for Overall Pipeline Speed

A slow build step directly extends the overall pipeline duration, affecting how quickly feedback reaches a developer after pushing a change — investing in proper caching configuration provides a meaningful, broadly felt benefit.

time docker build -t myapp .

Comparing build times with and without proper caching configuration demonstrates this benefit concretely.

Why the CI Docker Build Step Matters

Properly configuring this step — particularly its caching behavior — has an outsized effect on overall pipeline speed and therefore developer feedback loop speed, making it one of the more impactful steps to optimize within a containerized CI/CD pipeline.