microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.44k stars 2.6k forks source link

DockerCompose@0 uses outdated Docker-Compose utility 1.29.2 #17808

Open SillyCode opened 1 year ago

SillyCode commented 1 year ago

Since the update to Docker Engine and using the latest Windows-2019 image release 20230214.1. (The image contains the following Docker related versions: Docker 23.0.1 and Docker Compose V2 2.16.0)

And having the following task

- task: DockerCompose@0
      displayName: Spin up container
      inputs:
        containerregistrytype: 'Container Registry'
        dockerRegistryEndpoint: 'Schema-BuildReg'
        dockerComposeFile: 'Sources/Tests/Docker/docker-compose.yml'
        action: 'Run a Docker Compose command'
        dockerComposeCommand: 'up'
        arguments: '-d'

We are facing the following error: The current Compose file version is not compatible with your engine version. Please upgrade your Compose file to a more recent version, or set a COMPOSE_API_VERSION in your environment.

My Docker-Compose file:

version: "3.9"
services:
  sql-server-db:
    container_name: my-mssql
    image: my-mssql-image:latest
    ports:
      - "1433:1433"
    environment:
      SA_PASSWORD: "***************"
      ACCEPT_EULA: "Y"

Error log:

2023-02-19T08:22:09.0368683Z ##[debug]which 'docker-compose'
2023-02-19T08:22:09.0752496Z ##[debug]found: 'C:\ProgramData\Chocolatey\bin\docker-compose.exe'
2023-02-19T08:22:10.3052706Z [command]C:\ProgramData\Chocolatey\bin\docker-compose.exe -f D:\a\1\s\Sources\Tests\Docker\docker-compose.yml -f C:\agents\2.217.2\.docker-compose.1676794930282.yml -p SI up -d
2023-02-19T08:22:11.4679494Z Creating network "si_default" with the default driver
2023-02-19T08:22:12.0324536Z Pulling sql-server-db (***/my-mssql-image:latest)...
2023-02-19T08:22:14.8209567Z I2: Pulling from [i2-si-mssql](my-mssql-image:latest)
2023-02-19T08:32:54.0137344Z The current Compose file version is not compatible with your engine version. Please upgrade your Compose file to a more recent version, or set a COMPOSE_API_VERSION in your environment.
2023-02-19T08:32:54.9175774Z ##[debug]Exit code 1 received from tool 'C:\ProgramData\Chocolatey\bin\docker-compose.exe'
2023-02-19T08:32:54.9177252Z ##[debug]STDIO streams have closed for tool 'C:\ProgramData\Chocolatey\bin\docker-compose.exe'
2023-02-19T08:32:55.0020263Z ##[error]Pulling sql-server-db (***/my-mssql-image:latest)...
2023-02-19T08:32:55.0021455Z ##[debug]Processed: ##vso[task.issue type=error;]Pulling sql-server-db (***/my-mssql-image:latest)...
2023-02-19T08:32:55.0023243Z ##[error]The current Compose file version is not compatible with your engine version. Please upgrade your Compose file to a more recent version, or set a COMPOSE_API_VERSION in your environment.
2023-02-19T08:32:55.0025902Z ##[debug]Processed: ##vso[task.issue type=error;]The current Compose file version is not compatible with your engine version. Please upgrade your Compose file to a more recent version, or set a COMPOSE_API_VERSION in your environment.
2023-02-19T08:32:55.0117852Z ##[debug]task result: Failed
2023-02-19T08:32:55.0119880Z ##[error]The process 'C:\ProgramData\Chocolatey\bin\docker-compose.exe' failed with exit code 1

Specifically the line ##[error]The process 'C:\ProgramData\Chocolatey\bin\docker-compose.exe' failed with exit code 1

Looking at the build log. We can see that the issue is reported actually by Choco Docker Compose.

DockerCompose@0 uses Docker Compose version from C:\ProgramData\Chocolatey\bin\ Instead, it should take the latest Docker-Compose utility.

Going ahead to get the version of the Choco Docker Compose via:

- task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          C:\ProgramData\Chocolatey\bin\docker-compose.exe version

Outputted the following:

docker-compose version 1.29.2, build 5becea4c

Choco Docker Compose for reference: https://community.chocolatey.org/packages/docker-compose

As a workaround, I used below suggested solution

- task: PowerShell@2
      displayName: Run Docker-Compose
      inputs:
        targetType: 'inline'
        script: C:\ProgramData\docker\cli-plugins\docker-compose.exe -f docker-compose.yml up -d
lamelyan commented 1 year ago

I'm using the next version V2 of Docker Compose which uses the docker CLI 'compose' command instead of the docker-compose executable.

The task is looking for the 'docker-compose' executable and gives me an error.

Docker Compose was not found. You can provide the path to docker-compose via 'dockerComposePath'

shrralis commented 11 months ago

I've found a workaround for this. Add a new Bash task to download the latest Docker Compose:

wget -Odocker-compose https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64

chmod a+x ./docker-compose

In my Docker Compose task (0.*) under the Advanced Options -> Docker Compose executable Path set the $(System.DefaultWorkingDirectory)/docker-compose

walkindude commented 9 months ago

@shrralis thanks for sharing your workaround, you just saved my tail.

The task should be fixed to try docker compose if docker-compose fails though, as I just took a look at the source and it does exactly a which docker-compose, which of course won't work with recent versions of Docker.

nibdev commented 9 months ago

Here's another workaround (if you have Compose V2 as cli plugin). Specifiy the path to docker-compose as task parameter

grafik

ashishbhatt-afk commented 1 month ago

Here's another workaround (if you have Compose V2 as cli plugin). Specifiy the path to docker-compose as task parameter

grafik

Thank you for the workaround. But is there a permanent solution that we can expect in near future?

yuriy-sng commented 1 month ago

Workaround also helped with this error which appeared today to me:

[debug]arguments:

[debug] compose

[debug] --compatibility

[debug] -f

[debug] /agent/_work/1/s/docker-compose.ci.yaml

[debug] -p

[debug] MyProject

[debug] config

##[error]unknown flag: --compatibility