Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use docker compose V2 in Bitbucket Pipelines

Traditionally, I had been issuing

pip install docker-compose

instructions in my pipelines scripts for steps needing it, usually for integration tests.

This was convenient because it operates flawlessly with the docker binary provided by Bitbucket's docker service, and benefits from the pip cache since I am already using python images for those steps. But I'd rather work with up-to-date software, so I am looking for mechanisms to install docker-compose V2.

Ideally, the solution should

  • not install another docker binary, but reuse the one provided by Bitbucket's docker service
  • not require a specific runtime (unlike V1 requiring python)
  • benefit from some kind of cache to avoid downloading the compose plugin on every single pipeline.

Is anyone addressing this? What's your experience?

like image 865
N1ngu Avatar asked Oct 24 '25 16:10

N1ngu


1 Answers

One way to get it working is to download the latest release from github, place it in ~/.docker/cli-plugins and cache this folder.

definitions:
  caches:
    docker-cliplugins: ~/.docker/cli-plugins
  yaml-anchors:
    - &setup-docker-compose-latest-script >-
        wget --no-verbose --no-clobber https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 --output-document ~/.docker/cli-plugins/docker-compose
        || true
        ; chmod a+x ~/.docker/cli-plugins/docker-compose
        && ln --symbolic ~/.docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
pipelines:
  default:
    - step:
        services: [docker]
        caches: [docker-cliplugins]
        script:
          - *setup-docker-compose-latest-script
          - docker compose version

This needs wget --no-clobber to benefit from the cache.

Ideally this could be done in a reusable way with a pipe, just like you would with "setup" github actions. But because pipes are only mounted the clone directory and not the whole agent, here you have this yaml anchor.

like image 197
N1ngu Avatar answered Oct 27 '25 00:10

N1ngu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!