Installing Docker Compose v2 on Ubuntu 24.04

This guide describes how to install Docker Compose v2 as a plugin to the Docker CLI on Ubuntu 24.04 LTS. This method aligns with modern Docker standards and ensures compatibility with future updates and features.


Overview

Docker Compose v2 is integrated directly into the Docker CLI and is invoked using:

docker compose

Note: There is a space (not a hyphen) between docker and compose. The legacy docker-compose (v1) command is deprecated and should be avoided.


Prerequisites

  • Ubuntu 24.04 LTS
  • Root or sudo access

Step-by-Step Installation

1. Update System Packages

sudo apt update
sudo apt upgrade -y

2. Install Required Dependencies

sudo apt install ca-certificates curl gnupg -y

Create the directory for storing the GPG key:

sudo install -m 0755 -d /etc/apt/keyrings

3. Add Docker’s GPG Key

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

4. Set Up Docker 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

5. Install Docker and Compose Plugin

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

Post-Installation

Enable and Start Docker

sudo systemctl enable docker
sudo systemctl start docker

Allow Non-root Docker Usage (Optional)

To run Docker without sudo:

sudo usermod -aG docker $USER
newgrp docker

Note: You must log out and back in for group changes to take effect.


Verify Installation

Check Docker version:

docker --version

Check Compose plugin version:

docker compose version

Usage Example

Create a simple docker-compose.yml file:

version: "3.9"
services:
  hello:
    image: alpine
    command: ["echo", "Hello from Docker Compose v2"]

Run it:

docker compose up

You should see the message from the Alpine container.


Troubleshooting

  • If you see errors like docker: command not found, ensure Docker was installed correctly and is in your $PATH.
  • If docker compose fails silently or gets stuck, try using:
DOCKER_BUILDKIT=0 docker compose build

This disables BuildKit temporarily and can help isolate the problem.


Conclusion

Docker Compose v2 offers a streamlined experience as part of the Docker CLI. By using this plugin-based installation method, you’re future-proofing your development environment and simplifying container orchestration.

For questions or issues, contact the DevOps team or refer to the official documentation at https://docs.docker.com/compose/