0
0
DockerHow-ToBeginner · 4 min read

How to Install Docker Compose: Step-by-Step Guide

To install docker compose, download the official binary from Docker's GitHub releases and place it in your system's /usr/local/bin directory, then make it executable with chmod +x. Alternatively, if you have Docker Desktop, docker compose is included by default.
📐

Syntax

The basic syntax to install Docker Compose involves downloading the binary file, moving it to a directory in your system's PATH, and setting the right permissions.

  • curl -L [URL] -o /usr/local/bin/docker-compose: Downloads the Docker Compose binary.
  • chmod +x /usr/local/bin/docker-compose: Makes the binary executable.
  • docker compose version: Checks the installed version to confirm installation.
bash
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker compose version
Output
Docker Compose version v2.x.x
💻

Example

This example shows how to install Docker Compose on a Linux system by downloading the latest binary, making it executable, and verifying the installation.

bash
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker compose version
Output
Docker Compose version v2.20.2
⚠️

Common Pitfalls

Common mistakes when installing Docker Compose include:

  • Not using sudo when moving the binary to /usr/local/bin, causing permission errors.
  • Forgetting to make the binary executable with chmod +x.
  • Using the old docker-compose command instead of the new docker compose plugin syntax.
  • Not verifying the architecture of your system and downloading the correct binary.
bash
Wrong (missing executable permission):

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
# forgot chmod +x

docker compose version

Right:

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

docker compose version
📊

Quick Reference

Summary tips for installing Docker Compose:

  • Use the latest release from Docker Compose GitHub.
  • Ensure you download the binary matching your OS and architecture.
  • Use docker compose (space) command, not the legacy docker-compose (hyphen).
  • If you use Docker Desktop on Windows or Mac, Docker Compose is pre-installed.

Key Takeaways

Download the official Docker Compose binary matching your system architecture.
Place the binary in /usr/local/bin and make it executable with chmod +x.
Use the new 'docker compose' command syntax instead of 'docker-compose'.
Verify installation by running 'docker compose version'.
Docker Desktop users already have Docker Compose installed by default.