31

From my understanding, docker compose is the latest version. This is the one at least I installed from docker official documentation.

I am working on a project that use docker-compose in their makefile.

How could I forward all the calls (and their arguments) from docker-compose to docker compose ?

I created an alias: alias docker-compose="docker compose"

It works fine in terminal. But not in the make file.

0

3 Answers 3

80

One solution I've come up with is to create a little script.

File: /bin/docker-compose

Content:

docker compose "$@"

Alternatively, in order to respect previous container naming convention (with underscore delimiter _ over -):

docker compose --compatibility "$@"

To make the script executable: sudo chmod +x /bin/docker-compose.

You can check it with docker-compose version.

2
  • 4
    Note the container naming convention changed, with the old delimiter being _ and the new version using -. You can add the --compatibility flag to force the old format, for drop-in compatibility with existing scripts. Then content would be: docker compose --compatibility "$@" Sep 1, 2022 at 19:50
  • 4
    Cool oneliner based on the awesome suggestion above: ``` echo 'docker compose --compatibility "$@"' | sudo tee -a /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose ```
    – Mike R
    Nov 21, 2022 at 15:25
1

If you wish to avoid any additional scripts, I recommend you to :

  • create your alias (in your ~/.profile | ~/.bash|zshrc file)

    alias docker-compose="docker compose --compatibility $@"

  • source your ~/.profile|.zsh|bashrc file in your makefile.

1
0

Docker desktop comes with the option to alias docker compose v2 in Settings > General:

Docker compose alias option

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.