Cybersecurity Updates & Tools

Install Docker Compose on Ubuntu: Step-by-Step Setup Guide

Docker Compose is a command-line tool that lets you define and run multi-container Docker applications using a single YAML configuration file. Instead of managing containers individually with separate commands, you describe your entire application stack — services, networks, and volumes, in a docker-compose.yml file and bring it all up with one command. Docker Compose is widely used for local development environments, single-host application deployments, and automated CI/CD testing pipelines. It creates isolated, portable environments that can be shared and replicated across any machine running Docker. This guide covers how to install Docker Compose on Ubuntu and walks through a real-world multi-container example from start to finish.

Prerequisite: Docker must already be installed on your Ubuntu system before proceeding.

How to Install Docker Compose on Ubuntu

Docker Compose ships as a standalone binary. The recommended approach is to download it directly from the official GitHub releases page rather than Ubuntu’s repositories, which may carry an outdated version.

Check the Docker Compose GitHub releases page to confirm the latest stable version, then download the binary to /usr/local/bin:

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

Apply executable permissions to the downloaded file:

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

Confirm the installation by printing the version:

bashdocker-compose --version

A successful install returns a version string such as docker-compose version 1.25.5, build b02f1306. Always replace the version number in the download URL with the latest from the GitHub releases page before running the command.

Note: Docker Compose v2 ships as a Docker CLI plugin and is invoked as docker compose (no hyphen). The standalone v1 binary method above works reliably on Ubuntu 20.04 and remains widely supported for existing workflows.

Build a Multi-Container Application with Compose

The docker-compose.yml file is the heart of every Compose project — it defines all services your application needs and how they relate to each other. The following example builds a WordPress + MySQL stack, one of the most common multi-container setups in development.

Create your project directory and open a new Compose file:

bashmkdir my_app && cd my_appnano docker-compose.yml

Add the following configuration:

yamlversion: '3'services:  db:    image: mysql:5.7    restart: always    volumes:      - db_data:/var/lib/mysql    environment:      MYSQL_ROOT_PASSWORD: password      MYSQL_DATABASE: wordpress  wordpress:    image: wordpress    restart: always    ports:      - "8080:80"    environment:      WORDPRESS_DB_HOST: db:3306      WORDPRESS_DB_NAME: wordpress      WORDPRESS_DB_USER: root      WORDPRESS_DB_PASSWORD: password    depends_on:      - dbvolumes:  db_data:

Key points about this configuration:

  • restart: always ensures containers automatically restart after a crash or host reboot
  • depends_on guarantees MySQL starts before WordPress attempts a database connection
  • Named volumes (db_data) persist your database data across container restarts and recreations
  • Port mapping (8080:80) makes the WordPress site accessible at http://localhost:8080

Start the stack from your project directory:

bashdocker-compose up

Compose pulls the required images and starts both containers. Navigate to http://0.0.0.0:8080 — the WordPress installation wizard should appear within seconds. Press CTRL+C to stop.

Essential Docker Compose Commands

CommandWhat It Does
docker-compose up -dStarts all services in detached (background) mode
docker-compose psLists running services and their exposed port mappings
docker-compose stopGracefully stops services without removing containers
docker-compose downStops and removes containers, networks, and volumes

To uninstall Docker Compose entirely, remove the binary:

bashsudo rm /usr/local/bin/docker-compose

Docker Compose turns complex multi-container deployments into a clean, one-command workflow. Define your stack once in a docker-compose.yml and any team member can reproduce the full environment on any machine with docker-compose up, no manual setup required. As your projects grow, explore Compose features like environment variable files, health checks, and service scaling to handle more demanding workloads. Questions about your configuration? Leave a comment below.