How to upgrade docker-compose
My Ubuntu 20.04 installs version 1.25.0 of docker-compose while the most recent version is 2.0.1 (why is that?). Is there any method to force Ubuntu to install the latest version? If not, so I have to follow the official instructions, but the curl command is pointing to /usr/local/bin directory while on my machine it is installed on /usr/bin . So what is the safe method to upgrade my package?
The official Docker pages clearly explains how you install this on Linux. However this will be a «manual» installation, and not a package installation.
I never asked for a package installation. And the main reason I asked this question here is that the folder structure of what I have now is different from the instructions on docker page (as I clearly mentioned in the question).
Same issue for me, I use Ubuntu 18.04 and I have dc v1.17. The doc, for example for .env use : docs.docker.com/compose/environment-variables/#the-env-file specify version 1.28, so I would like to upgrade on my computer and my server.
2 Answers 2
Docker-compose takes place only in a binary file, so it is easy to put the last version !
First, if you have a previous installed version, remove it, in my case, I had version from main repository, so I ran :
sudo apt remove docker-compose
then go to https://github.com/docker/compose/releases and download, for example, for 2.2.3 : https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64
or other one
then move this file to :
sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
and
sudo chmod +x /usr/local/bin/docker-compose
check d-c runs correctly : docker-compose —version
that returns in my case : Docker Compose version v2.2.3
Under ubuntu 18.04, official docker are today at v19.03.13 and it is ok to work with compose v2
You are using an older release of Ubuntu, which generally runs older software. To run newer software, use a newer release of Ubuntu.
Note that the newest deb package for docker-compose is 1.27.
nobody has packaged 2.0.1 yet.
The BEST way to get newer deb packages is to help the Debian volunteers package it.
And I asked about the package on Github (refer to the link of official instructions I posted in my question).
You seem to want to install software from source (github). However, your Question was ambiguous — you only made that clear in a comment. This answer was written before you made that clarification. Consider editing your question to clearly ask the question that you want an answer for. You will get better help if you do.
jcberthon / update-docker-compose.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
#! /bin/bash |
# Copyright 2017-2018 Jean-Christophe Berthon |
# |
# Licensed under the Apache License, Version 2.0 (the «License»); |
# you may not use this file except in compliance with the License. |
# You may obtain a copy of the License at |
# |
# http://www.apache.org/licenses/LICENSE-2.0 |
# |
# Unless required by applicable law or agreed to in writing, software |
# distributed under the License is distributed on an «AS IS» BASIS, |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
# See the License for the specific language governing permissions and |
# limitations under the License. |
# # WARNING: this script is NOT production ready. A few checks are done. |
# It is given as a basis for building a production ready one, but you need |
# to add verifications for each stage. |
# # Quick Changelog |
# — made the script a bit more robust/safe (download the files unprivileged first |
# and «activate» them after simple verification when possible) |
# — corrected all feedback provided by [shellcheck](https://github.com/koalaman/shellcheck) |
set -eu |
function myerror |
echo >&2 » $@ « |
exit 1 |
> |
if ! MYTEMPDIR= » $( mktemp -d ) » ; then |
MYTEMPDIR= » /tmp/dc- $( dd status=none if=/dev/urandom bs=1 count=32 | sha256sum | cut -c-8 ) « |
mkdir » $ » || myerror » ERROR: could not create temporary directory. « |
fi |
# First download the latest release (no draft or prerelease, only full releases) of Docker Compose and |
# install it under /usr/local/bin/ |
files_list= » $( curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url \ |
| grep » docker-compose- $( uname -s ) — $( uname -m ) » | cut -d ‘ » ‘ -f 4 ) « |
curl -s -L » $( echo » $ » | grep » docker-compose- $( uname -s ) — $( uname -m ) $ » ) » \ |
-o » $ /docker-compose « |
curl -s -L » $( echo » $ » | grep » docker-compose- $( uname -s ) — $( uname -m ) .sha256$ » ) » \ |
-o » $ /docker-compose.sha256 « |
cksum_computed= » $( sha256sum » $ /docker-compose » | cut -c-64 ) « |
cksum_given= » $( cut -c-64 » $ /docker-compose.sha256 » ) « |
if [ » $ » != » $ » ] ; then |
myerror » ERROR: SHA256 downloaded does not match the file « |
fi |
# Make sure the permissions are correct |
chmod 0755 » $ /docker-compose « |
# Docker Compose shall print its version information now |
» $ /docker-compose » version |
# Install Docker Compose |
sudo mv » $ /docker-compose » /usr/local/bin/docker-compose |
sudo chown root:root /usr/local/bin/docker-compose |
# (optional) Install BASH completion for Docker Compose |
curl -s -L » https://raw.githubusercontent.com/docker/compose/ $( docker-compose version —short ) /contrib/completion/bash/docker-compose » \ |
-o » $ /docker-compose « |
sudo mv » $ /docker-compose » /etc/bash_completion.d/docker-compose |
# Make sure the permissions are correct |
sudo chmod 0644 /etc/bash_completion.d/docker-compose |
# Deleting temporary files and directories |
rm -Rf » $ « |
exit 0 |
Install the Compose plugin
Important
From July 2023 Compose V1 stopped receiving updates. It’s also no longer available in new releases of Docker Desktop.
Compose V2 is included with all currently supported versions of Docker Desktop. For more information, see Migrate to Compose V2.
Docker’s documentation refers to and describes Compose V2 functionality.
On this page you can find instructions on how to install the Compose plugin on Linux from the command line.
To install the Compose plugin on Linux, you can either:
Note
These instructions assume you already have Docker Engine and Docker CLI installed and now want to install the Compose plugin.
For Compose standalone, see Install Compose Standalone.
Install using the repository
- Set up the repository. Find distro-specific instructions in: Ubuntu | CentOS | Debian | Fedora | RHEL | SLES.
- Update the package index, and install the latest version of Docker Compose:
- For Ubuntu and Debian, run:
$ sudo apt-get update $ sudo apt-get install docker-compose-plugin
$ sudo yum update $ sudo yum install docker-compose-plugin
$ docker compose version Docker Compose version vN.N.N
Where vN.N.N is placeholder text standing in for the latest version.
Update Compose
To update the Compose plugin, run the following commands:
- For Ubuntu and Debian, run:
$ sudo apt-get update $ sudo apt-get install docker-compose-plugin
$ sudo yum update $ sudo yum install docker-compose-plugin
Install the plugin manually
Note
This option requires you to manage upgrades manually. We recommend setting up Docker’s repository for easier maintenance.
$ DOCKER_CONFIG=$DOCKER_CONFIG:-$HOME/.docker> $ mkdir -p $DOCKER_CONFIG/cli-plugins $ curl -SL https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
- Docker Compose for all users on your system, replace ~/.docker/cli-plugins with /usr/local/lib/docker/cli-plugins .
- A different version of Compose, substitute v2.20.0 with the version of Compose you want to use.
- For a different architecture, substitute x86_64 with the architecture you want.
$ chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
$ sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
$ docker compose version Docker Compose version v2.20.0
Compose file versions and upgrading
Warning
This page contains information on the legacy versions of Compose, also collectively referred to as Compose V1. From the end of June 2023 Compose V1 won’t be supported anymore.
The latest and recommended version of Compose is the Compose Specification. Make sure you switch to Compose V2 with the docker compose CLI plugin or by activating the Use Docker Compose V2 setting in Docker Desktop.
For more information, see the History of Compose.
The Compose file is a YAML file defining services, networks, and volumes for a Docker application.
The Compose file formats are now described in these references, specific to each version.
Reference file | What changed in this version |
---|---|
Version 3 | Version 3 updates |
Version 2 | Version 2 updates |
Version 1 (Deprecated) | Version 1 updates |
The topics below explain the differences among the versions, Docker Engine compatibility, and how to upgrade.
Compatibility matrix
This table shows which Compose file versions support specific Docker releases.
Compose file format | Docker Engine release |
---|---|
Compose specification | 19.03.0+ |
3.8 | 19.03.0+ |
3.7 | 18.06.0+ |
3.6 | 18.02.0+ |
3.5 | 17.12.0+ |
3.4 | 17.09.0+ |
3.3 | 17.06.0+ |
3.2 | 17.04.0+ |
3.1 | 1.13.1+ |
3.0 | 1.13.0+ |
2.4 | 17.12.0+ |
2.3 | 17.06.0+ |
2.2 | 1.13.0+ |
2.1 | 1.12.0+ |
2.0 | 1.10.0+ |
In addition to Compose file format versions shown in the table, the Compose itself is on a release schedule, as shown in Compose releases, but file format versions do not necessarily increment with each release. For example, Compose file format 3.0 was first introduced in Compose release 1.10.0, and versioned gradually in subsequent releases.
The latest Compose file format is defined by the Compose Specification and is implemented by Docker Compose 1.27.0+.
Looking for more detail on Docker and Compose compatibility?
We recommend keeping up-to-date with newer releases as much as possible. However, if you are using an older version of Docker and want to determine which Compose release is compatible, refer to the Compose release notes. Each set of release notes gives details on which versions of Docker Engine are supported, along with compatible Compose file format versions. (See also, the discussion in issue #3404.)
For details on versions and how to upgrade, see Versioning and Upgrading.
Versioning
There are three legacy versions of the Compose file format:
- Version 1. This is specified by omitting a version key at the root of the YAML.
- Version 2.x. This is specified with a version: ‘2’ or version: ‘2.1’ , etc., entry at the root of the YAML.
- Version 3.x, designed to be cross-compatible between Compose and the Docker Engine’s swarm mode. This is specified with a version: ‘3’ or version: ‘3.1’ , etc., entry at the root of the YAML.
The latest and recommended version of the Compose file format is defined by the Compose Specification. This format merges the 2.x and 3.x versions and is implemented by Compose 1.27.0+.
The Compatibility Matrix shows Compose file versions mapped to Docker Engine releases.
To move your project to a later version, see the Upgrading section.
Note: If you’re using multiple Compose files or extending services, each file must be of the same version — you cannot, for example, mix version 1 and 2 in a single project.
Several things differ depending on which version you use:
- The structure and permitted configuration keys
- The minimum Docker Engine version you must be running
- Compose’s behaviour with regards to networking
These differences are explained below.
Version 2
Compose files using the version 2 syntax must indicate the version number at the root of the document. All services must be declared under the services key.
Version 2 files are supported by Compose 1.6.0+ and require a Docker Engine of version 1.10.0+.
Named volumes can be declared under the volumes key, and networks can be declared under the networks key.
By default, every container joins an application-wide default network, and is discoverable at a hostname that’s the same as the service name. This means links are largely unnecessary. For more details, see Networking in Compose.
Note
With Compose version 2, when specifying the Compose file version to use, make sure to specify both the major and minor numbers. If no minor version is given, 0 is used by default and not the latest minor version. As a result, features added in later versions will not be supported. For example: