Adding backwards compatibility for 'docker-compose' with Docker Compose V2

Published: Posted by Patrick Henninger

Since the release of Docker Compose V2 it has not only been introduced as a core plugin to the new versions of Docker engine but most notably it's command synthax has changed from docker-compose to docker compose - this can lead to a lot of issues when working with projects that yet have to use Docker Compose V1 for some reason.

Luckily the plugins provided by the docker engine installation are standalone executables so we are able to run them directly without using the 'docker' command. We can use this knowledge to simply add an symbolic link that points to the Compose V2 plugin to our locally installed software directory using the following command:

[ -f /etc/resolv.conf ] && ln -s /usr/local/bin/docker-compose /usr/libexec/docker/cli-plugin/docker-compose || echo "Docker Compose V2 does not exist at the expected location!"

If the command completed without an error message we can check if the docker-compose command does work by running the following command and checking for it's output:

docker-compose -v

If every step has been followed correctly we will receive the following output:

Docker Compose version v2.x.x

You should now be able to use Docker Compose just as you did in version 1 and run all your old scripts and automations.

Attention: Accessing files in the libexec directory is safe but NOT supported and files in this directory are not guaranteed to be there! It is recommended to just update your scripts and replace 'docker-compose' with 'docker compose'.