How to upgrade docker-compose to latest version
Asked Answered
K

24

276

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.

Keef answered 15/4, 2018 at 6:12 Comment(0)
G
428

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
Gamophyllous answered 15/4, 2018 at 6:39 Comment(20)
Can you give some details about how it's not working?Gamophyllous
try updating path in /usr/local/bin/docker-compose and then run sudo chmod +x /usr/bin/docker-composeMyalgia
No need to move the file. The /usr/local/bin path should be in $PATH already. Just chmod in place. Answer updated to reflect this.Cottingham
You probably want to do sudo chmod 755 $DESTINATION instead of just +xCrownpiece
Neo, good catch. I typically just adjust perms to my need in case other things have set things how they need it. But here we are downloading a fresh file. Setting all perms makes sense.Cottingham
I follow this solution and my working doker-compose stops working and give an error like "usr/local/bin/docker-compose: 1: /usr/local/bin/docker-compose: Not: not found"Flugelhorn
@ChiragKalal Check that the binary is in that location with the proper permissions.Gamophyllous
I don't know what was the issue but I reinstall it and it works fine.Flugelhorn
Could the owner please update his answer? for most of us the path is incorrect, besides i already did it with the right path ^^Durwood
@Durwood Can you please be more specific about what you want the path updated to? /usr/local/bin is a pretty standard place to put global binaries not managed by the packaging system. The answer also mentions specifying "your favorite $PATH-accessible location" which indicates adjusting if your $PATH is different.Gamophyllous
If you don't want to install jq to get the latest version: VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')Stetson
@SaberHayati thanks, included this in the answer in case they don't have jq.Gamophyllous
@ChiragKalal if you get an error like /usr/local/bin/docker-compose: Not: not found it's probably because like me, you did sudo su before the last step (unnecessarily) and the subshell created doesn't have the $VERSION variable you just madeStertor
There is a typo in the line of Curl command, there is the correct: sudo curl -L https://github.com/docker/compose/releases/download/$\{VERSION\}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATIONUrbanist
I don't see why you would need to escape the braces, is anyone else having an issue with them?Gamophyllous
I added tab completions per docs.docker.com/compose/completion but not sure why they refer to version 1.29.2 in the URL - when I tried to most recent $VERSION it didn't work though so my tab completion might be for an older versionGimcrack
I mean you should just: docs.docker.com/compose/install :DSkimmia
I've used DESTINATION=/usr/bin/docker-composeVeer
and this is the curl command people with zsh: sudo curl -L github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATIONPasser
I had to remove the previous installation by which docker-compose and then rm [path of docker compose from the previous result]Sybilla
C
73

With the release of Docker-Compose v2, which was rewritten in Go, the original mentioned approch doesn't work anymore (thanks Denilson Sá Maia for pointing that out). If you have Docker Desktop, docker-compose command should work out-of-the-box. If you're on Linux, have a look at https://docs.docker.com/compose/install/linux/#install-using-the-repository, which for Ubuntu/Debian means:

 sudo apt-get update
 sudo apt-get install docker-compose-plugin

Working until July 2023

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.

Causalgia answered 21/5, 2018 at 18:44 Comment(7)
+1 great answer. Before: I had docker-compose version: docker-compose version 1.21.2, build a133471 So to upgrade to latest non-RC version, I found this to work in order to upgrade: 1) apt install python-pip to install PIP then pip install docker-compose to install the latest and then to check the version: docker-compose --version which gave me: docker-compose version 1.23.2, build 1110ad0Manzanares
pip install docker-compose was giving me "Requirement already satisfied: docker-compose" so I had to do apt-get purge docker-compose and hash -d docker-compose then pip install docker-compose to get docker-compose 1.24 on Ubuntu 18.04.Kuhn
After installing docker-compose by pip, I encountered this error: ImportError: cannot import name 'Context'M
So, to deal with this error, I reinstall docker package by pipM
No longer works for docker-compose v2+Encumbrance
Docker compose V2 was rewritten from Python to Go, and thus this answer here is obsolete and no longer works.Jaime
You're right, updated accordingly.Causalgia
L
34

If you tried sudo apt-get remove docker-compose and get E: Unable to locate package docker-compose, try this method :

This command must return a result, in order to check it is installed here :

ls -l /usr/local/bin/docker-compose

Remove the old version :

sudo rm -rf docker-compose

Download the last version (check official repo : docker/compose/releases) :

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

(replace 1.24.0 if needed)

Finally, apply executable permissions to the binary:

sudo chmod +x /usr/local/bin/docker-compose

Check version :

docker-compose -v
Legpull answered 26/4, 2019 at 14:23 Comment(4)
After doing this, I get this error - bash: /usr/bin/docker-compose: No such file or directoryMyrmeco
Add "v" before version number example : sudo curl -L "github.com/docker/compose/releases/download/v2.12.0/… -s)-$(uname -m)" -o /usr/local/bin/docker-composeCeliaceliac
If you got error like bash: /usr/bin/docker-compose: No such file or directory , just run sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose, then you'll resolve this issue.Situation
Newer versions: sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/bin/docker-composeScalp
S
24

If the above methods aren't working for you, then refer to this answer: https://stackoverflow.com/a/40554985

curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" > ./docker-compose
sudo mv ./docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
Stubble answered 19/7, 2018 at 17:35 Comment(6)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewBurnard
@Burnard Updated the answer. Thank you for the suggestionStubble
It seems to be extremely slow optionMargalit
This is by far the best solution, just needed to change the version number and I was able to update docker-compose in under a minute! With regards to the comment made by @Margalit - this isn't a slow option at all, it's just dependent on your internet speed as it downloads the docker-compose binary directly.Medley
Lol, maybe the mirrors servers were upgraded withing the last three years, idk. I was on 300Mbps back then so probably the issue wasn't on my side.Margalit
Add "v" before version number example : sudo curl -L "github.com/docker/compose/releases/download/v2.12.0/… -s)-$(uname -m)" -o /usr/local/bin/docker-composeCeliaceliac
K
23

Here is another oneliner to install the latest version of docker-compose using curl and sed.

curl -L "https://github.com/docker/compose/releases/download/`curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | sed 's#.*tag/##g' && echo`/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
Korman answered 24/1, 2019 at 6:46 Comment(4)
This should be the correct answer! The most simple/ short and useful solution!Furiya
After doing this, I get this error - bash: /usr/bin/docker-compose: No such file or directoryMyrmeco
@martinho I had the same issue on Ubuntu 20.04, I had to logout and login in order to get it working.Discrepancy
✅ This should be the correct answer as it is small and works like charm! A great oneliner.Lopsided
B
21

Based on @eric-johnson's answer, I'm currently using this in a script:

#!/bin/bash
compose_version=$(curl https://api.github.com/repos/docker/compose/releases/latest | jq .name -r)
output='/usr/local/bin/docker-compose'
curl -L https://github.com/docker/compose/releases/download/$compose_version/docker-compose-$(uname -s)-$(uname -m) -o $output
chmod +x $output
echo $(docker-compose --version)

it grabs the latest version from the GitHub api.

Bennink answered 20/7, 2018 at 4:44 Comment(4)
I encountered with an error in 4th line: zsh: parse error near )'`M
just tested it out here, but it seems to work fine (debian 10 with zsh). You sure you copied it correctly?Bennink
Try double quoting the URLs as sometimes the shell can get a bit grabby.Blanche
Not necessary to echo $(docker-compose --version), doing docker-compose --version gives a simple result.Palatable
A
19

Simple Solution to update docker-compose

This will remove the existing binary of docker-compose and install a new version.

sudo cd /usr/local/bin && sudo rm -rf docker-compose
sudo curl -SL https://github.com/docker/compose/releases/download/v2.24.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x docker-compose

for the latest version visit https://github.com/docker/compose/releases and replace the latest one with v2.24.3

Archipenko answered 17/11, 2021 at 5:41 Comment(5)
This one is good and worked for me but it has some issues that you can solve it easily by reading the issuesBoule
@KasirBarati can you please share the issue So we make this issue freeArchipenko
Just this part did not work for me: sudo rm /usr/local/bin/docker-compose. I tried to update the answer but I could not since at that moment the edit queue was full. Thank you so much for your comment.Boule
@KasirBarati thanks sudo rm /usr/local/bin/docker-compose is used to remove the existing docker-compose file but in some cases, it is installed in different locations like /usr/local/bin/docker/docker-compose that the reason first command gave error Hope it will helpArchipenko
TBH no, it was not the case for me.Boule
F
14

Do it in three steps. (showing for apt-get installs)

  1. Uninstall the last one. e.g. for apt-get installs

sudo apt-get remove docker-compose

  1. Install the new one (https://docs.docker.com/compose/install/)

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

and then

 sudo chmod +x /usr/local/bin/docker-compose
  1. Check your version

docker-compose --version

Fabe answered 8/4, 2021 at 8:53 Comment(2)
Works great, to automatically get the latest version, you could also replace step 2 by: 2a) COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep 'tag_name' | cut -d\" -f4) and then 2b) sudo curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-composeScheme
one additional step ln -sf /usr/local/bin/docker-compose /usr/bin/docker-composeCompensatory
F
8

I was trying to install docker-compose on "Ubuntu 16.04.5 LTS" but after installing it like this:

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

I was getting:

-bash: /usr/local/bin/docker-compose: Permission denied

and while I was using it with sudo I was getting:

sudo: docker-compose: command not found

So here's the steps that I took and solved my problem:

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
Flunkey answered 6/6, 2020 at 20:3 Comment(1)
I think that 1-line command should still work from rootSecant
B
6

On mac (also working on ubuntu):

sudo curl -L "https://github.com/docker/compose/releases/download/<release-version>/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

NOTE: write the as here: https://github.com/docker/compose/releases

Berard answered 26/5, 2022 at 8:52 Comment(1)
Docker compose is also included with Docker Desktop, so you can use the "Check for updates" from the menu under the Docker icon in the Mac menu barLauzon
H
5

use this from command line: sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Write down the latest release version

Apply executable permissions to the binary:

sudo chmod +x /usr/local/bin/docker-compose

Then test version:

$ docker-compose --version
Handlebar answered 17/9, 2018 at 20:7 Comment(0)
O
4

Docker Engine and Docker Compose Plugin

Since Microsoft took over Docker they worked on porting docker-compose to their Docker Engine CLI plugins. For future support and updates I would recommend using docker compose plugin (Notice the missing dash) which can be install via the docker-compose-plugin package. The following instructions assume that you are using Ubuntu as Distro or any Distro thats using apt as package manager.

Installation Preparations

Update your mirrors:

sudo apt-get update

Make sure the following packages are installed:

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

After that add the official Docker GPG Key:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

And finally add the the stable repository:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Also make sure Docker Engine and other needed dependencies are installed:

sudo apt-get install docker-ce docker-ce-cli containerd.io

Installation of docker compose plugin

sudo apt-get install docker-compose-plugin

Any future updates of the plugin are easily applied via apt.
For further reference take a look at the official installation instructions of Docker Engine and Docker Compose.

Oxide answered 26/5, 2022 at 9:36 Comment(0)
D
3

If you installed with pip, to upgrade you can just use:

 pip install --upgrade docker-compose

or as Mariyo states with pip3 explicitly:

 pip3 install --upgrade docker-compose
Dipterocarpaceous answered 7/8, 2019 at 12:5 Comment(1)
in my case it was pip3 install --upgrade docker-composeQuattrocento
C
3

Using latest flag in url will redirect you to the latest release of the repo

As OS name is lower case in github's filename, you should convert uname -s to lower case using sed -e 's/\(.*\)/\L\1/'.

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s|sed -e 's/\(.*\)/\L\1/')-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
Concern answered 15/1, 2022 at 9:27 Comment(0)
R
2

This is the method of installing docker compose version 2.12.x

Update debian package manager

# apt-get update
# apt-get install docker-compose-plugin

Then install the plugin manualy

 DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
 mkdir -p $DOCKER_CONFIG/cli-plugins
 curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

Give permisson of execution of file

chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

Last test the installation

docker compose version
// Docker Composer Version v2.12.2
Remediosremedy answered 18/11, 2022 at 11:55 Comment(0)
B
1

After a lot of looking at ways to perform this I ended up using jq, and hopefully I can expand it to handle other repos beyond Docker-Compose without too much work.

# If you have jq installed this will automatically find the latest release binary for your architecture and download it
curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | jq --arg PLATFORM_ARCH "$(echo `uname -s`-`uname -m`)" -r '.assets[] | select(.name | endswith($PLATFORM_ARCH)).browser_download_url' | xargs sudo curl -L -o /usr/local/bin/docker-compose --url
Blanche answered 20/9, 2018 at 16:53 Comment(0)
F
1

On ubuntu desktop 18.04.2, I have the 'local' removed from the path when using the curl command to install the package and it works for me. See above answer by Kshitij.

Ferrara answered 6/4, 2019 at 14:3 Comment(0)
M
1

Use,

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose

$ docker-compose -v
Myrmeco answered 13/11, 2021 at 8:43 Comment(0)
W
1

In my case, using Windows + WSL2 with Ubuntu 20.04, was necessary only this:

sudo apt update

and then:

sudo apt upgrade

Wexford answered 29/4, 2022 at 10:59 Comment(0)
G
1

Centos/RHEL

Follow my answer below if you're using Centos7 with an x86-64 architecture. This answer is also available in my github.

Stop Your Docker Containers

I noticed other answers did not talk about stopping your docker containers/images instances before attempting to upgrade gracefully. Assumptions are inevitable but can be costly. Onward we go!

Options to update Docker-Compose

There are 2 options to upgrade docker-compose if you first downloaded and installed docker-compose using the Curl command.

  1. Using Curl, jq package, and Github's direct URL to the docker-compose repository.
  2. Using Curl, Sed, and Github's direct URL to the docker-compose repository.

Note: some of the commands below require "sudo" privileges.

Demonstration

The script below was saved to a file called "update_docker_compose.sh". You need to give this file executable permissions.

Like so:

chmod +x update_docker_compose.sh

"docker_docker_compose.sh" file content:

#!/bin/bash

# author: fullarray (stackoverflow user)
# Contribution shared on: stackoverflow.com
# Contribution also available on: github.com
# date: 06112022

# Stop current docker container running
docker stop containerID

# Remove current docker network running
docker rm containerID

# Remove image of target application(s)
docker image rm imageID

# Delete either dangling (unatagged images) docker containers or images or network
docker system prune -f

# This step depends on the jq package. 
# Uncomment jq package installation command below if using Centos7 x86-64.
# sudo yum install jq

# Declare variable to get latest version of docker-compose from github repository
compose_version=$(curl https://api.github.com/repos/docker/compose/releases/latest | jq .name -r)

# Declare variable to target installation directory
target_install_dir='/usr/local/bin/docker-compose'

# Get OS and build (assumes Linux Centos7 and x86_64)
get_local_os_build=$(uname -s)-$(uname -m)

# Execute curl command to carry download and installation operation
curl -L https://github.com/docker/compose/releases/download/$compose_version/docker-compose-$get_local_os_build -o $target_install_dir

# Use chmod to modify permissions to target installation directory (to make it executable)
chmod +x $target_install_dir

# Print docker-compose version to terminal to verify upgrade
$(docker-compose --version)

Edit the script with variables specific to your environment

The script above has a few variables you need to edit with values specific to your docker environment. For instance, you need to replace container ID and image ID with the values that the following commands output.

docker ps

and

docker images output

Once you finalize creating the file (including the edits). Switch to the directory that contains the file. For example, if you created the file in /home/username/script/update_docker_compose.sh

cd /home/username/script

Last, run the script by executing the following

./update_docker_compose.sh

Option 2

Create a script file name "update_docker_compose.sh"

Edit the file and add the following content:

#!/bin/bash

# author: fullarray (stackoverflow user)
# Contribution shared on: stackoverflow.com
# Contribution also available on: github.com
# date: 06112022

# Stop current docker container running
docker stop containerID

# Remove current docker network running
docker rm containerID

# Remove image of target application(s)
docker image rm imageID

# Delete either dangling (unatagged images) docker containers or images or network
docker system prune -f

# Declare variable to target installation directory
target_install_dir='/usr/local/bin/docker-compose'

# Get OS and build (assumes Linux Centos7 and x86_64)
get_local_os_build=$(uname -s)-$(uname -m)

# Execute curl and sed command to carry out download and installation operation
# compose_latest_version=$(curl -L "https://github.com/docker/compose/releases/download/`curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | sed 's#.*tag/##g' && echo`/docker-compose-$get_local_os_build") -o $target_install_dir

# Use chmod to modify permissions to target installation directory (to make it executable)
chmod +x $target_install_dir

# Print docker-compose version to terminal to verify upgrade
$(docker-compose --version)

Edit the script with variables specific to your environment

The script above also has a few variables you need to edit with values specific to your docker environment. For instance, you need to replace container ID and image ID with the values that the following commands output.

docker ps

and

docker images output

Once you finalize creating the file (including the edits). Switch to the directory that contains the file. For example, if you created the file in /home/username/script/update_docker_compose.sh

cd /home/username/script

Last, run the script by executing the following

./update_docker_compose.sh
Grapefruit answered 11/6, 2022 at 19:16 Comment(0)
W
-1

If you have homebrew you can also install via brew

$ brew install docker-compose

This is a good way to install on a Mac OS system

Whoso answered 25/10, 2018 at 14:23 Comment(0)
S
-1

Most of these solutions are outdated or make you install old version. To install the latest

sudo apt  install jq

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

sudo curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Subject answered 26/4, 2021 at 23:10 Comment(0)
T
-1

Well, my case was pretty weird. I am using wsl2, and Docker Desktop (Windows 11). I stop getting this error after rename the folder "docker" to "config-dev-server" and update de Dockerfile like this this:

COPY ./docker/apache/apache2.conf /etc/apache2/apache2.conf

to

COPY ./config-dev-server/apache/apache2.conf /etc/apache2/apache2.conf
Transduction answered 22/6, 2022 at 13:57 Comment(0)
A
-2

With a newer Docker Desktop for Mac 3.3.0, you don't need to install Docker Compose as a seperate package. Docker Compose comes as a first class citizen installed with Docker by default. Check out the below CLI:


docker compose version
Docker Compose version 2.0.0-beta.1%
Aeromarine answered 29/5, 2021 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.