I noticed that docker-compose 1.x is gently being dropped in favor of the new v2:
https://www.docker.com/blog/announcing-compose-v2-general-availability/
So I then removed my docker-compose
v1.x command (I think it was the way to go, but I cannot find the old documentation on how to install/uninstall docker-compose anymore):
$ sudo rm -rf /usr/local/bin/docker-compose
Then I installed the new version according to the doc:
$ sudo apt-get install docker-compose-plugin
and voilà:
$ docker compose version
Docker Compose version v2.5.0
But all my scripts which used to call docker-compose
(with a dash) are no more working. Obviously.
Hence my question; how could I alias the new compose command to docker-compose
?
Is it sufficient to add this line to by .bashrc
file?
$ echo "alias docker-compose='docker compose'" >> ~/.bashrc
$ source ~/.bashrc
The absolute easiest solution is to make an alias, like you state in your question:
This will work without any issue.
Also, I would recommend installing Docker Compose using the
apt
packagedocker-compose-plugin
, and not by manually installing withcurl
, unless you have a very good reason to do so.By installing with
apt
(which is the recommended way on Ubuntu), you ensure that you can update Docker Compose automatically with new Docker releases usingapt upgrade
or even with unattended upgrades.Adding an alias to
.bashrc
will work for most cases, but for some scripts may not work.IMHO creating a small script named
docker-compose
to yourPATH
that just passes arguments todocker compose
is a better way to solve the problem.This answer might help: https://stackoverflow.com/a/72187587/11418220
It was not 100% clear to me but there are two ways to install compose on the documentation:
the former, by
apt install docker-compose-plugin
a second way (user either the first way or the second, but not both) by manually downloading the binary with
curl
but it misses some details I think, especially the newly created folder is not in the defaultpath
. Here's how I proceeded to install it globally (i.e. in/usr/local/...
):or in one shot:
Then you got the two ways of calling it, the transition is smoother: