How to Cache Docker Layers in Bitbucket Pipelines
Bitbucket has a built-in docker cache for the layer store, plus registry-backed Buildx caching for cross-run reuse.
Add the predefined docker cache to a step to persist the local layer store, or push a registry cache with Buildx for reuse across branches and runners.
Built-in docker cache on a step
The docker cache persists the daemon's layer store between runs of this step.
bitbucket-pipelines.yml
pipelines:
default:
- step:
name: Build image
services:
- docker
caches:
- docker
script:
- docker build -t app:$BITBUCKET_COMMIT .Gotchas
- The built-in
dockercache caches the local layer store; for cross-branch reuse, push a registry cache with Buildx instead. - Building images requires the
dockerservice on the step, ordocker buildhas no daemon. - Bitbucket caches expire after 7 days and have a size cap; very large layer stores may not fully persist.
Frequently asked questions
How do I cache Docker Layers in Bitbucket Pipelines?
Add the predefined docker cache to a step to persist the local layer store, or push a registry cache with Buildx for reuse across branches and runners.
Built-in docker cache on a step?
The docker cache persists the daemon's layer store between runs of this step.
Related guides
How to Build a Multi-Arch Docker Image in Bitbucket PipelinesBuild a multi-architecture Docker image in Bitbucket Pipelines with the docker service, Buildx, and QEMU, pus…
How to Define a Custom Pipeline Trigger in Bitbucket PipelinesCreate a manually triggered Bitbucket Pipelines workflow under the custom: section so an operator can run a n…
How to Pass Artifacts Between Steps in Bitbucket PipelinesPass build artifacts between steps in Bitbucket Pipelines with the artifacts: keyword and glob paths so a lat…