Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Install the Latest Version of Docker Compose v2

blog/cards/install-the-latest-version-of-docker-compose-v2.jpg

This can be handy for brand new releases that haven't been pushed to your operating system's package manager or Docker Desktop yet.

Quick Jump: Demo Video

Prefer video? Here it is on YouTube.

Let’s say you’re running native Linux with Debian or Ubuntu and you’ve installed Docker officially. Then you’ve run sudo apt-get update && apt-cache policy docker-compose-plugin but you’re not seeing the latest version of Docker Compose based on its releases.

Or maybe you’re using Docker Desktop on macOS or Windows and you want the latest version which hasn’t shipped there yet. NOTE: I verified this strategy works with macOS using DD but not Windows (it should tho!).

Fortunately Docker makes it easy to manually install the Docker Compose v2 plugin. They have a dedicated page for that in their docs.

Here’s the TL;DR to install it in your user’s home directory:

If you’re using Windows you’ll want to convert the shell commands below into manual steps that you perform or script it with PowerShell. It really boils down to downloading 1 file in a specific directory and making it executable.

# Ensure the necessary directories exist.
$ DOCKER_CONFIG="${DOCKER_CONFIG:-$HOME/.docker}"
$ mkdir -p "${DOCKER_CONFIG}/cli-plugins"

# Which version do you want to install?
$ VERSION=v2.23.0

# Using macOS with Docker Desktop? Let's first make a backup of the existing
# symlink so you don't overwrite the version that comes with DD.
$ mv "${DOCKER_CONFIG}/cli-plugins/docker-compose" "${DOCKER_CONFIG}/cli-plugins/docker-compose-bak"

# This command is set up to work with Linux on amd64. If you're using a different
# CPU architecture or macOS / Windows please read the paragraphs below.
$ curl -SL "https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-linux-x86_64" -o "${DOCKER_CONFIG}/cli-plugins/docker-compose" && chmod +x "${_}"

# Verify it works.
$ docker compose version
Docker Compose version v2.23.0

The above curl command is set up to work with native Linux (amd64 CPU architecture). There’s a whole bunch of different OS and CPU architecture binaries in the assets section of a specific release on the releases page.

If you’re on macOS or Windows with Docker Desktop you’ll want to modify the docker-compose-linux-x86_64 file name to match your operating system and CPU architecture.

Once the release is available in your OS’ package manager or DD can you remove the manually downloaded file from your cli-plugins/ directory and install it officially. You can rename your bak symlink back to the original if you’re using DD too.

The video below goes over installing it and verifying it works on native Linux.

Demo Video

References

Timestamps

  • 0:18 – Checking the latest version in apt’s repos vs GitHub releases
  • 1:38 – Going over how this is going to work
  • 3:08 – Manually installing the very latest version
  • 5:12 – Verifying it works and removing the custom latest version
  • 6:14 – It should work well with Docker Desktop

Will you end up installing Docker Compose this way? Let us know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments