How To

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.

Cyber Defence

Recent Posts

Install VirtualBox on Ubuntu from Ubuntu Repositories

The simplest approach is Ubuntu's multiverse repository. A single command installs both VirtualBox and the Extension…

8 minutes ago

Install Vagrant on Ubuntu: Setup and Getting Started Guide

If your team needs identical development environments across different operating systems, Vagrant is the tool that makes…

18 minutes ago

Install GCC on Ubuntu: build-essential and Multiple Versions

GCC; the GNU Compiler Collection is the backbone of open-source software development on Linux. It supports…

31 minutes ago

Install Redis on Ubuntu: Configuration and Remote Access

Redis is an open-source, in-memory key-value store built for raw speed and versatility. It works equally well as…

22 hours ago

Install Skype on Ubuntu: Two Methods That Actually Work

Skype doesn't ship with Ubuntu by default it's a proprietary application owned by Microsoft and…

22 hours ago

Install PHP on Ubuntu: Complete Setup Guide for Apache & Nginx

PHP is the backbone of the web. Frameworks like Laravel, WordPress, and Magento all run on…

22 hours ago