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.

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.
- Prerequisites and Supported Releases
- Step 1: Setting Up the Official Docker APT Repository
- Step 2: Installing Docker Engine and Docker Compose V2
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.
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.
Complete step-by-step administrator guide to installing Docker Compose V2 on Ubuntu 24.04 LTS (Noble Numbat). Covers official Docker APT repository configuration, installing the modern docker-compose-plugin, writing production compose.yaml definitions, and managing multi-container stacks.
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:
- A server running Ubuntu 24.04 LTS (Noble Numbat) or Ubuntu 22.04 LTS.
- A non-root user account with
sudoadministrative 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.
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.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install Docker on Ubuntu — Install and configure the core Docker Engine on Ubuntu systems.
- How to Install Podman on Ubuntu: Rootless Container Alternative to Docker — Explore rootless container alternatives with Podman Compose.
- Initial Server Setup on Ubuntu 24.04 LTS — Configure server security, SSH keys, and UFW before deploying containers.
Authoritative References and Official Documentation

UNIX and Linux System Administration Handbook, 5th Edition
Frequently Asked Questions
Quick answers to common questions and configurations
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..env in your project directory and interpolates its variables into compose.yaml (e.g. ${DATABASE_PASSWORD}).docker compose up -d --build to force Docker Compose to rebuild container images before recreating the services.docker compose restart (for example: docker compose restart web).Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
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.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!