How to use GitLab registry caching?

I’m trying to speed up builds by using the registry caching backend for Docker-in-Docker builds in my CI. I have a self-managed 17.4.2 CE.

I’ve been following this example … Make Docker-in-Docker builds faster with Docker layer caching | GitLab Docs

And this link says the default driver supports the ‘registry’ backend. Cache storage backends | Docker Docs

I have the following in my .gitlab-ci.yaml.

default:
  image: docker:28.1.1
  services:
    - docker:28.1.1-dind

script:
  - docker context create my-builder
  - docker buildx build --push -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    --cache-to type=registry,ref=$CI_REGISTRY_IMAGE/cache-image,mode=max
    --cache-from type=registry,ref=$CI_REGISTRY_IMAGE/cache-image .

The problem is that GitLab CI is reporting the following in the log.

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.

I’ve been useing Deploy → Container Registry which has images inside it, so AFAIK, it’s enabled.

Thoughts?

Hey @rrlangly,

Looks like the issue might be that you’re still using the default docker driver with buildx, which doesn’t support ’ cache-toforregistrycaching. To use the registry backend, you'll need to switch to a driver that supports it, typicallydocker-container. You can do that by setting up a builder explicitly with docker buildx create, use driver docker-container`.

1 Like

Got it, thanks.

maybe the error message should read

"please use the docker-container driver for gitlab-runner combined with docker buildx so you can enable caching. your current driver is docker where caching will not be functional "