HostingArtisan Community for Web Artisans
CI/CD Pipelines & DevOps

GitLab CI/CD with Docker 24.x—best practices for caching layers?

3 replies · 7 views
#1 — Original Post
25 Mar 2026, 19:00
A
argomaster

We're running GitLab CI on Hetzner with Docker 24.0.6, and our pipeline is taking 18 minutes per build. Most of the time is spent rebuilding Docker layers that haven't changed.

Currently using:

docker build -t myapp:latest .
docker push myapp:latest

I've looked at BuildKit and layer caching, but I'm unsure about the best approach for GitLab CI specifically. Should I be using:

  • DOCKER_BUILDKIT=1 with inline cache?
  • A private registry for intermediate stages?
  • Something else entirely?

Anyone running similar setups? What's your go-to strategy?

Edited at 25 Mar 2026, 21:51

#2
25 Mar 2026, 21:10
M
multicloud

BuildKit with inline cache is solid, but here's the real win: use type=registry cache backend in your .gitlab-ci.yml. Push intermediate layers to your registry and GitLab CI will reuse them automatically. Set DOCKER_BUILDKIT=1 and add --cache-from type=registry,ref=myapp:buildcache to your build command. Way faster than inline and doesn't bloat your main image. We cut our build times from 20min to 5min with this approach on Hetzner.

#3
25 Mar 2026, 21:20
Y
yaml_warrior

18 min is rough. tbh, skip inline cache for now—it's flaky in CI. Instead, set up a local registry mirror on your Hetzner box using Docker's --cache-from flag pointing to your last build image. Also make sure you're using .dockerignore aggressively—a lot of time gets wasted on unnecessary COPY layers. You can also split your Dockerfile into a separate base layer that rarely changes and push that independently.

#4
25 Mar 2026, 21:30
A
argomaster

Thanks both! Yeah, the type=registry cache backend sounds promising—I'll try that first since we're already pushing to GitLab's registry anyway. @yaml_warrior, good point about inline cache being flaky; I was worried about that. Will test the registry approach before spinning up a local mirror.

You need to be logged in to reply.

Log in to Reply

Cookie Preferences

We use cookies to improve your experience and analyse traffic. You can accept all or use only essential cookies.

Essential Always on
Analytics Optional
Marketing Optional
Privacy · Terms ·