Docker Compose in BitBucket Pipelines

Viewed 2163

I have the following BitBucket Pipeline

pipelines:
  default:
    - step:
        name: Build and test
        image: mcr.microsoft.com/dotnet/core/sdk:3.1
        caches:
              - dotnetcore
        script:
              - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER}
              - dotnet restore
              - dotnet build --no-restore --configuration Release
    - step:
        name: API Test
        image: mcr.microsoft.com/dotnet/core/sdk:3.1
        trigger: manual
        services:
          - customdocker
        script:
          - docker-compose -f docker-compose-api-tests.yml build
          - docker-compose -f docker-compose-api-tests.yml up
definitions:
    services:
        customdocker:
            image: docker/compose:1.28.5

I am trying to run docker-compose inside the pipeline. I get the following error:

  • docker-compose -f docker-compose-api-tests.yml build bash: docker-compose: command not found

Can anyone help? Thanks

2 Answers

I solved this using:

pipelines:
  default:
    - step:
        name: Build
        image: mcr.microsoft.com/dotnet/core/sdk:3.1
        caches:
              - dotnetcore
        script:
              - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER}
              - dotnet restore
              - dotnet build --no-restore --configuration Release
    - step:
        name: Postman Tests
        image: python:3.8.1
        services:
            - docker
        caches:
            - docker
            - pip
        script:
            - pip install docker-compose
            - docker network create dockernet
            - docker-compose -f docker-compose-api-tests.yml build
            - docker-compose -f docker-compose-api-tests.yml up --exit-code-from postman
definitions:
  services:
    docker:
      memory: 3072

You are trying to use a tool that is not present in the default image used by pipelines. You have two ways to resolve that:

  1. install the tool during your build (you did that in your own answer)

  2. use a different build image that already contains your required tool

See bitbuckets documentation.

Bitbucket advises users to explicitly pick a build image because the defaults are pretty old and rarely updated. for your usecase the docker-compose image might be good.

Related