Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade docker-compose to latest version

I have installed docker-compose using the command

sudo apt install docker-compose

It installed docker-compose version 1.8.0 and build unknown

I need the latest version of docker-compose or at least a version of 1.9.0

Can anyone please let me know what approach I should take to upgrade it or uninstall and re-install the latest version.

I have checked the docker website and can see that they are recommending this to install the latest version'

sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

But before that, I have to uninstall the present version, which can be done using the command

sudo rm /usr/local/bin/docker-compose

but this can be used only when the installation was done using curl. I am not sure if the installation was done by curl as I have used

sudo apt install docker-compose

Please let me know what should I do now to uninstall and re-install the docker-compose.

like image 864
Sam_2207 Avatar asked Sep 27 '22 00:09

Sam_2207


2 Answers

First, remove the old version:

If installed via apt-get

sudo apt-get remove docker-compose

If installed via curl

sudo rm /usr/local/bin/docker-compose

If installed via pip

pip uninstall docker-compose

Then find the newest version on the release page at GitHub or by curling the API and extracting the version from the response using grep or jq (thanks to dragon788, frbl, and Saber Hayati for these improvements):

# curl + grep
VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')

# curl + jq
VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | jq .name -r)

Finally, download to your favorite $PATH-accessible location and set permissions:

DESTINATION=/usr/local/bin/docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION
sudo chmod 755 $DESTINATION
like image 333
Eric M. Johnson Avatar answered Oct 24 '22 12:10

Eric M. Johnson


The easiest way to have a permanent and sustainable solution for the Docker Compose installation and the way to upgrade it, is to just use the package manager pip with:

pip install docker-compose

I was searching for a good solution for the ugly "how to upgrade to the latest version number"-problem, which appeared after you´ve read the official docs - and just found it occasionally - just have a look at the docker-compose pip package - it should reflect (mostly) the current number of the latest released Docker Compose version.

A package manager is always the best solution if it comes to managing software installations! So you just abstract from handling the versions on your own.

like image 65
jonashackt Avatar answered Oct 24 '22 11:10

jonashackt