Problem to solve
We want to build a Docker image during out CI pipeline using docker buildx
and --cache-to
/--cache-from
. I already have this working on a personal project just fine, but having copied over the content of the job YAML to our build pipeline it doesn’t work as it fails with the error…
ERROR: Cache export is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-cache-backends/
In the job on my personal project I copied this from it works just fine with no complaints.
I’ve checked the docker info
and the versions of the docker:git
& docker:dind
and both are using the same value. I’ve even disabled our company runners so I’m running the job on the Gitlab runners, as my version is, but still the same problem.
I can’t, for the life of me, work out what’s causing the difference between the 2 projects.
Steps to reproduce
Try creating a job using the config files below & build a docker image from a Dockerfile and see if it works. Because the configs are so similar I really can’t advise on how to replicate this.
Configuration
Version from my project that works…
build_images:
stage: build
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_COMMIT_TAG'
image: docker:27.3.1
services:
- docker:27.3.1-dind
before_script:
- 'docker info'
- 'docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY'
script:
- 'ci_merge_source_branch=$(echo "${CI_COMMIT_MESSAGE}" | grep "^Source branch: " | sed -e ''s/^Source branch: //'' || true)'
- 'source_branch_cache_from_arg=""'
- '[[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" && -n "${ci_merge_source_branch}" ]] &&
source_branch_cache_from_arg="--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/php:${ci_merge_source_branch}"'
- 'docker buildx build
--cache-to type=inline
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/php:${CI_COMMIT_REF_SLUG}
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/php:${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/php:${CI_DEFAULT_BRANCH}
--platform linux/amd64
-t ${CI_REGISTRY_IMAGE}/php:${CI_COMMIT_REF_SLUG}
--target frankenphp_prod .'
- docker push ${CI_REGISTRY_IMAGE}/php:${CI_COMMIT_REF_SLUG}
Version that is not working for us…
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/pipeline/#customization
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
include:
- template: 'Security/SAST.gitlab-ci.yml'
stages:
- 'test'
pest_tests:
stage: 'test'
image: docker:27.3.1
services:
- docker:27.3.1-dind
variables:
IMAGE_TAG: '${IMAGE_PREFIX}app-php:$PHP_IMAGE_VERSION'
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- 'docker info'
- 'cp .env.ci .env'
- 'echo "$CI_JOB_TOKEN" | docker login registry.gitlab.com --username gitlab-ci-token --password-stdin'
script:
- 'docker buildx build
--cache-to inline
--cache-from type=registry,ref=$IMAGE_TAG
--cache-from type=registry,ref=${IMAGE_PREFIX}app-php:main
--target frankenphp_dev
--tag $IMAGE_TAG
--push
./app'
- 'docker compose run --rm php vendor/bin/pest'
sast:
stage: 'test'
Versions
Please select whether options apply, and add the version information.
- Self-managed
-
GitLab.com
SaaS - Dedicated
- Self-hosted Runners
Versions
- GitLab: GitLab Enterprise Edition 17.6.0-pre e360ca366ce
- GitLab Runner:…
Version: 16.9.1 Git revision: 782c6ecb Git branch: 16-9-stable GO version: go1.21.7 Built: 2024-02-28T16:51:21+0000 OS/Arch: linux/amd64
Helpful resources
- Check the FAQ for helpful documentation, issues/bugs/feature proposals, and troubleshooting tips.
- Before opening a new topic, make sure to search for keywords in the forum search
- Check the GitLab and GitLab Runner projects for existing issues. If you encounter a bug, please create a bug report issue.
- Review existing troubleshooting docs.
Thanks for taking the time to be thorough in your request, it really helps!