DevOps

Why Docker Buildx Changed My CI/CD Game Forever

Asep Alazhari

Discover how migrating from traditional docker build to Docker Buildx with cloud builders cut my build times in half and eliminated server resource bottlenecks.

Why Docker Buildx Changed My CI/CD Game Forever

Why I Finally Said Goodbye to Server Side Docker Builds

Watching GitLab pipelines queue for 15 minutes became my daily routine. The server maxed out CPU on every Docker build, blocking other deployments and burning through resources. After years of accepting this as normal, I finally decided enough was enough.

The solution came through Docker Buildx with cloud builders. Subscribing to Docker Pro annually and migrating the entire CI/CD pipeline transformed everything. Build times dropped by 67 percent, server load plummeted, and my team stopped complaining about slow deployments.

If you are running Docker builds inside your server and facing resource bottlenecks, slow build times, or inconsistent performance, this guide is for you.

Understanding the Problem with Traditional Docker Build

When you run docker build directly on your GitLab runner or server, several issues emerge. First, you compete for resources with other jobs. Second, build caching becomes unpredictable. Third, your server hardware limits your build performance.

In my production frontend project, each build took around 8 to 12 minutes on our OVH server. The server struggled with multiple concurrent builds, and we had three separate deployment jobs fighting for the same resources.

Here is what a typical traditional build looked like in our GitLab CI configuration before migration.

build_job:
    stage: build
    script:
        - docker build -t myapp:latest .
        - docker push myapp:latest

Simple, right? But behind the scenes, this consumed massive CPU cycles, heated up the server, and blocked other pipelines.

What Makes Docker Buildx Different

Docker Buildx extends the docker build command with new capabilities. It supports multi platform builds, advanced caching strategies, and most importantly, remote builders.

The game changer is Docker Build Cloud. When you subscribe to Docker Pro, you get access to cloud builders that handle your builds remotely. Your server becomes a coordinator, not a workhorse.

Think of it like this. Instead of cooking a feast in your tiny kitchen, you order from a restaurant with industrial grade equipment. The food arrives faster, your kitchen stays clean, and you can handle multiple orders simultaneously.

Also Read: Mastering Automated Docker Tagging in GitLab CI/CD: A Practical Guide

My Migration Journey Step by Step

The migration required three main changes to our GitLab CI/CD pipeline. First, installing buildx in the runner environment. Second, configuring the cloud builder. Third, updating the build commands.

Here is the exact before script we implemented.

before_script:
    - docker info
    - echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
    - |
        apk add curl jq
        ARCH=${CI_RUNNER_EXECUTABLE_ARCH#*/}
        BUILDX_URL=$(curl -s https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-lab-releases.json | jq -r ".latest.assets[] | select(endswith(\"linux-$ARCH\"))")
        mkdir -vp ~/.docker/cli-plugins/
        curl --silent -L --output ~/.docker/cli-plugins/docker-buildx $BUILDX_URL
        chmod a+x ~/.docker/cli-plugins/docker-buildx
    - docker buildx create --use --driver cloud myorg/builder-cloud

This script does several critical things. It downloads the latest buildx binary for the runner architecture. It installs buildx as a Docker CLI plugin. Then it creates a buildx builder using the cloud driver, pointing to my Docker organization team.

The beauty here is that this runs once per job, and the setup overhead is minimal compared to build time savings.

The Build Command Transformation

The actual build command changed from a simple docker build to docker buildx build with specific flags.

script:
    - |
        docker buildx build \
          --platform linux/amd64 \
          --tag $DOCKER_HUB_IMAGE:$CI_PIPELINE_IID \
          --push .

Notice the key differences. We specify the platform explicitly. We push directly during build, eliminating a separate push step. Most importantly, the build happens in the cloud, not on our server.

After the cloud build completes, we pull the image back to deploy it to our containers.

- docker pull $DOCKER_HUB_IMAGE:$CI_PIPELINE_IID
- docker rm -f app-fe-prod-container-1 || true
- docker run -d -p 3202:3000 --name app-fe-prod-container-1 $DOCKER_HUB_IMAGE:$CI_PIPELINE_IID

This hybrid approach gives us the best of both worlds. Fast cloud builds and local deployment flexibility.

Real Performance Numbers

Let me share the actual results from our production pipeline. Before buildx, our average build time was 10 minutes and 30 seconds. After migration, it dropped to 3 minutes and 15 seconds.

Looking at pipeline 5400 from our GitLab API data, the build job completed in just 194 seconds. That is a 67 percent reduction in build time. The deployment jobs that follow finish in under 2 minutes each.

But speed is not the only win. Our server CPU usage during builds dropped from 90 percent spikes to barely 20 percent. This freed up resources for other critical services running on the same machine.

Cost wise, the Docker Pro subscription at around 9 dollars per month per user is negligible compared to the time savings. My team pushes 20 to 30 builds daily. That is 3.5 hours saved every single day.

Also Read: GitLab CI/CD: Dynamic Variables Across Environments

Lessons Learned and Best Practices

Migration was not without hiccups. Initially, I forgot to set the platform flag, resulting in ARM images that would not run on our x86 servers. Always specify your target platform explicitly.

Another gotcha was authentication. Make sure your Docker Hub credentials have access to the Build Cloud service. The error messages are not always clear when this fails.

I also learned to separate build and deployment jobs. Running five container instances across three servers works better when the build stage finishes first and deployment happens in parallel afterward.

For environment variables, inject them before the build using echo commands to a .env file. This keeps secrets out of the Dockerfile while still making them available during the Next.js build process.

before_script:
    - echo NEXT_PUBLIC_BASE_URL_API=$NEXT_PUBLIC_BASE_URL_API >> .env
    - echo NEXT_PUBLIC_API_KEY=$NEXT_PUBLIC_API_KEY >> .env
    # Additional env vars

This pattern works perfectly with Next.js standalone output and keeps our Docker images portable.

When Should You Make the Switch

Not every project needs Docker Buildx with cloud builders. If you are building once a day and have plenty of server resources, the traditional approach works fine.

But if you are in any of these situations, migration makes sense. Multiple daily builds competing for resources. Slow build times impacting developer productivity. Need for multi platform image support. Desire to reduce server load and heat.

For teams using GitLab CI/CD with Docker, the integration is seamless. The investment in learning buildx pays off quickly, especially if you are already comfortable with Docker concepts.

The Docker Pro subscription is worth it when your time and infrastructure costs exceed the monthly fee. For my use case, the ROI was obvious within the first week.

Your Next Steps

Start by testing buildx locally with docker buildx build commands. Verify your Dockerfile works with the buildx builder. Then create a test pipeline in GitLab that uses the cloud driver.

Monitor your first few builds closely. Check logs, verify image pushes, and confirm deployments succeed. Once stable, migrate your remaining pipelines.

Remember to update your documentation and inform your team about the new build process. The commands look different, and troubleshooting cloud builds requires understanding the buildx architecture.

The combination of GitLab CI/CD, Docker Buildx, and Docker Build Cloud transformed our deployment workflow. Faster builds, lower server load, and happier developers. That is what modern DevOps should feel like.

Your infrastructure deserves better than waiting for slow builds. Give Docker Buildx a try, and watch your pipeline times plummet.

Back to Blog

Related Posts

View All Posts »