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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Docker Cache not working

Edited

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

pipelines:
custom:
create-dockerfile-based-cache:
- step:
name: Create Dockerfile based cache of backend
runs-on:
- self.hosted
- linux
script:
- 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}'
caches:
- docker
services:
- docker

definitions:
services:
docker:
image: docker:dind
memory: 7168

options:
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
REPOSITORY TAG IMAGE ID CREATED SIZE
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.
Sep 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:

- export DOCKER_BUILDKIT=0

Kind regards,
Theodora

@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.
Sep 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,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events