How to differentiate docker caching in bitbucket-pipelines

xmoex
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 3, 2025

We are using Docker in our pipelines. Usually we build an image (image A) with buildkit using buildkit inline cache. 

Afterwards we run commands using the built image. Using the default docker cache this works very nicely as the image is usually cached which is what we want.

Now we started to use an external docker image (image B) which is very big, far too big to ever fit into the cache. Now there's the problem:

  • if we enable the docker cache the pipeline takes ages trying to compress image B, (together with image A) only to figure out they wont fit. 
  • if we disable the docker cache the pipeline has to build image A every time even though it would by itself fit into the cache if we were to omit image B

The question is: How can we use docker caching but prevent trying to send image B to the cache?

1 answer

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 4, 2025

G'day, @xmoex 

Welcome to the community!

If I understand this correctly, you don't want the pipeline to cache image B because it's too big and you wanted to see if it's possible to skip them. If yes, I believe it's not possible to do so, one things you can consider perhaps splitting them into two steps for example:


pipelines:   default:     - step:         name: Build and Cache Image A         caches:           - docker         script:           - export DOCKER_BUILDKIT=1           - docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t myorg/image-a:latest .           - docker push myorg/image-a:latest     - step:         name: Use Image A and Image B         script:           - docker pull           - docker pull myorg/image-a:latest           - docker pull external-registry/image-b:latest           - docker run myorg/image-a:latest command-to-run           - docker run external-registry/image-b:latest another-command-to-run

Regards,
Syahrul

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events