Docker Compose is a tool for defining and running multi-container Docker applications with a single YAML file. Docker Compose v2 is now bundled with Docker Engine as a plugin. This guide installs and demonstrates it on Ubuntu 24.04 LTS.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • Docker Engine installed
  • A user in the docker group

Step 1 – Verify Docker Compose is Installed

Docker Compose v2 is included as a Docker plugin:

docker compose version

Step 2 – Install Docker Compose Standalone (optional)

To install the standalone binary separately:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

Step 3 – Create a docker-compose.yml File

Create a sample WordPress + MySQL Compose file:

mkdir ~/wordpress && cd ~/wordpress
nano docker-compose.yml

Add:

version: '3.9'
services:
  db:
    image: mysql:8.0
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: wppass

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: wppass
      WORDPRESS_DB_NAME: wordpress

volumes:
  db_data:

Step 4 – Start the Services

Start in detached mode:

docker compose up -d

Step 5 – Manage the Stack

Common Compose commands:

docker compose ps          # list services
docker compose logs -f     # follow logs
docker compose stop        # stop without removing
docker compose down        # stop and remove containers
docker compose down -v     # also remove volumes

Step 6 – Scale a Service

Run multiple instances of a service:

docker compose up -d --scale wordpress=3

Conclusion

Docker Compose is configured on Ubuntu 24.04 LTS. It simplifies deploying multi-service applications using a single docker-compose.yml file. Use it for development environments and single-host production deployments.