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.