GitLab Runner: Speeding up repeat builds
This documentation is part of the Building Docker images guide. You can view the complete guide here: Build and push Docker images efficiently from your GitLab CI/CD pipelines using Stackhero runners and Docker-in-Docker.
👋 Welcome to the Stackhero documentation!
Stackhero offers a simple GitLab Runner cloud solution that makes running your GitLab CI/CD jobs efficient and straightforward. Here’s what you can expect:
- Unlimited CI/CD minutes: run your pipelines as often as you need, with no per-minute billing or unexpected fees.
- Multiple concurrent jobs: speed up your development by running several jobs in parallel.
- The Docker executor with Docker-in-Docker support: easily build and push container images as part of your CI/CD workflows.
- Works seamlessly with both GitLab.com and self-managed GitLab instances.
- A private, dedicated infrastructure with fast NVMe/SSD storage ensures stable and predictable build performance.
- Available in 🇪🇺 Europe and 🇺🇸 USA regions to meet your team's needs.
Save time: you can connect your first GitLab Runner and start running pipelines in just a few minutes!
Your runner's disk persists between pipelines, allowing you to reuse image layers as a build cache. This can make repeated builds much faster. Here is an example configuration:
build-cached:
stage: build
image: docker:29
services:
- name: docker:29-dind
alias: docker
variables:
DOCKER_HOST: "tcp://docker:2375"
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
# Pull the latest image to seed the cache (if it exists):
- docker pull "$CI_REGISTRY_IMAGE:latest" || true
- docker build --cache-from "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:latest" .
- docker push "$CI_REGISTRY_IMAGE:latest"
This approach allows your builds to leverage Docker's layer caching, so only new or changed layers are rebuilt.