Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Docker Cache not working

maiermic September 25, 2023

I'm using docker-compose to run some pipelines. Since the compose file contains multiple services with different images, the docker cache gets to big to be cached. Hence, I only like to cache the image of the service that is build. Everything else can be downloaded from a registry. My 

image: atlassian/default-image:4.20230906

- step:
name: Create Dockerfile based cache of backend
- self.hosted
- linux
- docker image ls -a
- docker-compose -f docker-compose.yml -f docker-compose.bitbucket-pipelines.yml build backend
- docker image ls -a
- >
docker image inspect $(docker image ls -aq) --format {{.Size}}
| awk '{totalSizeInBytes += $0} END {print totalSizeInBytes}'
- docker
- docker

image: docker:dind
memory: 7168

docker: true #enabling docker daemon
size: 2x

I run the pipeline twice on the same commit. I expect the cache to be created on the first run and to be used on the second run, such that the build does not have to be run again.

The first run works as expected. It shows no images before building, builds from scratch, shows the images after the build

+ docker image ls -a
backend latest d196ad1ca1c2 4 seconds ago 1.04GB

and uploads the cache.

The second run downloads the cache and shows the same image ID as built in the first run. Nevertheless, it builds from scratch. The cache seems to have no effect. Why?

The Dockerfile starts with

FROM --platform=linux/amd64 php:8.2-apache
RUN apt-get update \
&& apt-get install ...

Is php:8.2-apache not part of the cache? If it is, why is the RUN command run again in the second pipeline run? The command didn't change. It should also be part of the cache.

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 26, 2023

Hi @maiermic,

Just a heads up, I moved your post to a new question since you are reporting an issue with a completely different setup.

I tried to reproduce this and I see that docker-compose uses BuildKit, which is the reason why the cache is not used. The predefined docker cache used for caching the layers produced during Docker Build operations does not cache layers produced when using BuildKit:

If you want to use the Docker cache with this pipeline, you can add the following command at the beginning of your yml file's script in order to disable BuildKit:


Kind regards,

maiermic September 28, 2023

@Theodora Boudale Thanks, are there any plans to support caching with BuildKit in a similar fashion in the future?

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 29, 2023

Hi @maiermic,

This is not on the roadmap at the moment. We have a feature request in our issue tracker:

You can add your vote to it to express your interest (by selecting the Vote for this issue link) and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy here and any updates will be posted in the feature request.

Kind regards,

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events