gradle-docker-compose-plugin icon indicating copy to clipboard operation
gradle-docker-compose-plugin copied to clipboard

Use 'docker compose' instead of 'docker-compose'

Open stewartbryson opened this issue 2 years ago • 12 comments

Have you considered porting this to use the new compose functionality in the Docker daemon?

Thank you.

stewartbryson avatar Sep 16 '21 19:09 stewartbryson

Hello, it would be nice to support both Docker Compose 1.x and V2 but unfortunately I don't have time for this improvement now. Any help welcome 🙏

augi avatar Sep 21 '21 17:09 augi

Can this be used as a workaround?

$ echo '#!/usr/bin/env bash

docker compose $@' > ~/bin/docker-compose
$ chmod 755 ~/bin/docker-compose
$ which docker-compose
/Users/me/bin/docker-compose
$ docker-compose version
Docker Compose version v2.3.3

Alternatively uninstall the regular docker-compose and just do ...

ln -s $HOME/.docker/cli-plugins/docker-compose /usr/local/bin/docker-compose

... or similarily on macOS:

ln -s /Applications/Docker.app/Contents/Resources/cli-plugins/docker-compose  /usr/local/bin/docker-compose

henrik242 avatar Mar 15 '22 10:03 henrik242

I've tried to add support in the PR at #348. Might be too simplistic, but at least shouldn't break anything with the default config.

henrik242 avatar Mar 15 '22 15:03 henrik242

@henrik242 Actually, there is compose-switch utility that works like a bridge between docker-compose and docker compose: https://github.com/docker/compose-switch/

augi avatar Mar 15 '22 19:03 augi

@stewartbryson @henrik242 What is please your use-case for docker compose usage? According to the docs: image

So the aliasing should still work, so there shouldn't be any reason for docker compose support 🤔

augi avatar Mar 15 '22 19:03 augi

compose-switch requires a separate install, which we'd rather not have to push on all users of our project.

The default bundled docker-compose in Docker Desktop is v1.29.2 from may 2021, and doesn't support the latest compose-spec

$ ls -l /usr/local/bin/docker-compose
lrwxr-xr-x  1 root  admin  62 25 aug  2021 /usr/local/bin/docker-compose -> /Applications/Docker.app/Contents/Resources/bin/docker-compose
$  ls -l /usr/local/bin/docker
lrwxr-xr-x  1 root  admin  54 17 nov  2020 /usr/local/bin/docker -> /Applications/Docker.app/Contents/Resources/bin/docker
$ /usr/local/bin/docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020
$ /usr/local/bin/docker compose version
Docker Compose version v2.3.3

henrik242 avatar Mar 16 '22 07:03 henrik242

I didn't mean compose-switch as replacement for a feature of this plugin, I just wanted to mention it as an alternative for the solution proposed by you 👌

augi avatar Mar 16 '22 07:03 augi

Imagine we introduced the proposed ComposeV2 switch - then if enabled, you would have to force all the users of your project to switch to a latest version of Docker Desktop that supports docker compose.

What would be the perfect solution would be not to introduce the ComposeV2 switch at all, but make the decision internally, if use docker-compose or docker compose. But I'm not sure how to detect that Compose V2 should be used 🤔

augi avatar Mar 16 '22 07:03 augi

You could of course check versions of both docker-compose and docker compose and pick the latest one, but debugging errors could be tricky if the user is not aware of what is happening.

I'd rather have a manual switch for now.

henrik242 avatar Mar 16 '22 07:03 henrik242

I just had to spend some extra time making this work as "docker-compose" is not an official alias for "docker compose" in the main installation.

Could there be a config variable saying "useComposeV2" that can, eventually, have its default set to true? That'd require maintaning both codes for a little while, though.

biancarosa avatar Aug 21 '22 14:08 biancarosa

Our docker-compose version switched from 1.29.2 to 2.10.2 on our build images and we are getting invalid tag reference names due to the service name prefixes changing to - to _ in our CI environment.

> Task :composeBuild FAILED
invalid tag "6a186a353405cef76803929dcf99538d_ads-decision-engine_-localstack": invalid reference format

FAILURE: Build failed with an exception.

Anyone have a workaround that works with the new docker-compose version 2 or do I need to get the platform team to revert the docker-compose version?

bassco avatar Aug 29 '22 17:08 bassco

If anyone comes across the above issue, the workaround is to set the following env var COMPOSE_COMPATIBILITY=1 which restores the v1 service name prefix.

bassco avatar Aug 30 '22 10:08 bassco

Looks like the time is coming soon: warnings in the latest update of docker desktop.

https://docs.docker.com/compose/migrate/

robertfmurdock avatar May 26 '23 14:05 robertfmurdock

Thanks. Feel free to prepare a new PR for this feature 🙏

augi avatar Jun 02 '23 13:06 augi

we also can take a look at the continiously supported solution from the latest spring-boot 3.1 org.springframework.boot:spring-boot-docker-compose https://tpbabparn.medium.com/spring-boot-3-1-integrated-docker-compose-on-development-environment-spring-webflux-example-1ddcbfe052f

rt-works avatar Jun 02 '23 13:06 rt-works

Won't this tie you to the Spring eco system? The nice thing of the avast gradle-docker-compose-plugin for me is that it is quite standalone and has a clear boundary between code and Docker, with Spring it usually gets blurry and/or you need many dependencies.

jvwilge avatar Jun 05 '23 07:06 jvwilge

As a workaround we created a fake docker-compose script.

#!/bin/sh

/usr/bin/docker compose "$@"

rt-works avatar Jun 05 '23 07:06 rt-works

@rt-works You shouldn't quote $@

henrik242 avatar Jun 05 '23 08:06 henrik242

worked for me with quoting

rt-works avatar Jun 05 '23 08:06 rt-works

@rt-works For simple commands, yeah. With more options it might not.

henrik242 avatar Jun 05 '23 08:06 henrik242

Good to know :) For the "up -f docker-compose.yaml" which is passed there by gradle plugin that was sufficient.

rt-works avatar Jun 05 '23 08:06 rt-works

For those interested, I've opened a PR to add this feature to the plugin. If anyone has time to do additional testing or to review, it would be much appreciated.

joecotton-wk avatar Aug 08 '23 05:08 joecotton-wk

Fixed by #410

augi avatar Aug 08 '23 13:08 augi