Website Vidya
Linux & ServersStep-by-Step Guide

How to Install Docker Compose on Ubuntu 24.04

Learn how to install docker compose on ubuntu 24.04 with Docker Compose V2 plugin, compose.yaml syntax, environment variables, and daemon setup.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install Docker Compose on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to install docker compose on ubuntu 24.04 with Docker Compose V2 plugin, compose.yaml syntax, environment variables, and daemon setup.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Setting Up the Official Docker APT Repository
  • Step 2: Installing Docker Engine and Docker Compose V2
Grounded in full engineering runbookWebsiteVidya AI Engine

Running isolated individual containers with docker run is sufficient for quick tests, but production applications require orchestrating multiple interconnected services.

Docker Compose is the standard multi-container orchestration tool that allows developers to define services, networks, and persistent storage volumes inside a single declarative YAML file.

Historically, Docker Compose was distributed as a standalone Python-based binary invoked as docker-compose (Compose V1, now deprecated).

Modern Docker architectures utilize Docker Compose V2, a high-performance Go binary integrated directly into the Docker CLI as a native plugin invoked via docker compose.

Advertisement

In this tutorial, we demonstrate how to install docker compose on ubuntu 24.04, verify the Compose V2 plugin, deploy a multi-container stack, and manage service lifecycles.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

Advertisement
  • A server running Ubuntu 24.04 LTS (Noble Numbat) or Ubuntu 22.04 LTS.
  • A non-root user account with sudo administrative privileges.
  • Docker Engine installed (or willingness to install Docker during this guide).
  • A terminal connection via SSH or local console.

Step 1: Setting Up the Official Docker APT Repository

To install Docker Compose V2, you must configure the official Docker Debian repository rather than relying on outdated distribution packages.

First, install prerequisite packages for HTTPS repository communication:

Download and configure the official Docker GPG signing key in /etc/apt/keyrings/:

# Install prerequisite packages:
sudo apt update
sudo apt install -y ca-certificates curl gnupg

# Create directory for apt keyrings:
sudo install -m 0755 -d /etc/apt/keyrings

# Download and store official Docker GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the official Docker APT repository source list:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 2: Installing Docker Engine and Docker Compose V2

With the official repository registered, refresh your APT package cache to index Docker's software packages.

Advertisement

Install Docker Engine, the CLI, and the docker-compose-plugin package:

This installs the modern Docker Compose V2 plugin natively into your system:

# Update package lists:
sudo apt update

# Install Docker Engine and the Docker Compose plugin:
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Verify Docker Compose V2 installation:
docker compose version
# Expected output: Docker Compose version v2.29.2

Enabling Non-Root Docker Access

By default, communicating with the Docker daemon requires root permissions via sudo.

To run Docker and Docker Compose commands without typing sudo every time, add your current user to the docker system group:

# Add active user to the docker group:
sudo usermod -aG docker $USER

# Apply new group membership to current shell:
newgrp docker

# Verify without sudo:
docker compose version

Step 3: Creating a Multi-Container compose.yaml Application

Docker Compose V2 natively supports the standard compose.yaml filename specification (in addition to legacy docker-compose.yml).

Create a project directory for a multi-container web application comprising an Nginx web server reverse proxying to a backend service:

Create a dedicated configuration file named compose.yaml:

# ~/my-web-stack/compose.yaml
services:
  web:
    image: nginx:alpine
    container_name: web_proxy
    restart: always
    ports:
      - "8080:80"
    networks:
      - app_network
    depends_on:
      - redis

  redis:
    image: redis:alpine
    container_name: cache_service
    restart: always
    volumes:
      - redis_data:/data
    networks:
      - app_network

networks:
  app_network:
    driver: bridge

volumes:
  redis_data:
    driver: local

Step 4: Launching and Managing Compose Services

Launch your multi-container stack in detached background mode using docker compose up -d.

Docker Compose pulls necessary container images, configures isolated virtual networks, initializes persistent volumes, and launches containers in dependency order:

# Navigate to your project directory:
cd ~/my-web-stack

# Launch containers in detached mode:
docker compose up -d

# Terminal execution output:
# [+] Running 4/4
#  ✔ Network my-web-stack_app_network  Created
#  ✔ Volume "my-web-stack_redis_data"  Created
#  ✔ Container cache_service           Started
#  ✔ Container web_proxy               Started

# Inspect status of running services:
docker compose ps

# View streaming logs across all services:
docker compose logs -f

Stopping and Cleaning Up Compose Stacks

When you need to stop your application stack, use docker compose down.

This command gracefully stops containers and removes virtual network bridges while preserving persistent volumes on disk:

# Stop and remove containers and networks:
docker compose down

# To stop and also remove persistent data volumes:
# docker compose down -v

Advanced Features: Environment Variables, Healthchecks, and Scaling

Docker Compose V2 includes production-grade features for environment configuration, container health verification, and horizontal service scaling.

To avoid hardcoding sensitive passwords or configuration variables inside compose.yaml, create a .env file in your project directory.

Compose automatically reads .env and interpolates variables into service definitions:

# .env file in project root
APP_PORT=8080
CACHE_PORT=6379
REDIS_PASSWORD=SecureProductionSecret2026!
LOG_LEVEL=info

Configuring Healthchecks for Automated Self-Healing

You can define native container healthchecks to monitor service responsiveness and delay dependent service startup until readiness checks pass:

Compose evaluates health commands at defined intervals and automatically restarts unhealthy containers:

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost/"]
  interval: 30s
  timeout: 5s
  retries: 3
  start_period: 10s

Scaling Services Horizontally with --scale

When traffic spikes occur, you can scale stateless backend services horizontally across multiple container instances:

Execute the --scale flag to dynamically increase container replica counts behind a load balancer:

# Scale backend service to 3 container replicas:
docker compose up -d --scale web=3

# Verify active running replicas:
docker compose ps

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

docker: 'compose' is not a docker command

Cause: The modern docker-compose-plugin package is not installed on the system.

Resolution: Install the plugin package via APT using the official Docker repository.

sudo apt install -y docker-compose-plugin

permission denied while trying to connect to the Docker daemon socket

Cause: Current user is not a member of the docker group.

Resolution: Add user to docker group and refresh shell session with newgrp docker.

sudo usermod -aG docker $USER && newgrp docker

Port is already allocated / bind failed

Cause: Another process on the host is already listening on the specified host port (e.g. 8080).

Resolution: Check port usage with ss -tulpen | grep 8080 and adjust ports in compose.yaml.

ss -tulpen | grep 8080

Security Best Practices and Hardening

Do not expose internal database or cache ports (such as Redis port 6379) directly on public host interfaces in compose.yaml.

Use environment variable files (.env) to store secrets and ensure .env is added to .gitignore.

Audit container images regularly using docker scout or Trivy to identify known CVE vulnerabilities.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
docker-compose (with hyphen) was the legacy Compose V1 utility written in Python. docker compose (with space) is the modern Compose V2 utility written in Go and integrated directly into the Docker CLI as an official plugin.
Yes. Docker Compose automatically looks for a file named .env in your project directory and interpolates its variables into compose.yaml (e.g. ${DATABASE_PASSWORD}).
Run docker compose up -d --build to force Docker Compose to rebuild container images before recreating the services.
Execute docker compose restart (for example: docker compose restart web).
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout