How to switch from “docker-compose” to “docker compose”
The CLI API for docker compose has changed recently. It used to be a single-word command with the two words separated by a hyphen. Since docker compose became available as a docker plugin, you could also run it by calling the docker command followed by the word compose.
You might run into issues if you want to run scripts that call docker compose using the old style. Here is a short guide on how to create a system-wide alias for docker-compose
. Remember, if we create an alias in our bashrc file, it only applies to our user terminal sessions. Even if we added it to the root user bashrc, it would still not apply to other actions like systemd services.
A way to solve this issue is to create a new bash script and place it somewhere in the global system executable path. I chose /usr/bin
. Once there, I used sudo privileges to create a bash script called docker-compose that consists of a single line (after the shebang!) calling the new docker compose plugin and passing along all the arguments it received. And that’s it. You can now call docker-compose and will pass all arguments along to docker compose. You can find a short summary of the commands below:
cd /usr/bin
sudo vim docker-compose
#### contents of the file ######
#~/bin/bash
docker compose "$@"
#### end contents #####
sudo chmod +x docker-compose