Support Online
Skip to main content

Docker Compose Installation and Usage (Ubuntu 22.04)

Docker Compose installation allows managing multiple container architectures with a single file.

What will you learn in this guide?

In this guide, you will learn how to install Docker Compose on Ubuntu 22.04.
You will see how to manage single-service and multi-service applications.
You will implement WordPress + MySQL and modern use cases.

Technical Summary

This guide explains how to install Docker Compose v2 on Ubuntu 22.04.
The goal is to manage multi-container applications with YAML file.
Steps; installation, sample structure, operation, scaling and error resolution.


Prerequisites

  • A server with Ubuntu 22.04 installed
  • User with authority sudo
  • Docker Engine must be installed

This step adds Docker's official repository and installs the Compose plugin.

sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
  • This command adds the Docker signature key.


sudo apt install docker-compose-plugin
  • This command installs Docker Compose v2.

To verify installation:


docker compose version

2. Step: Creating docker-compose.yml File

  1. This step defines a simple Nginx service.

mkdir ~/compose-demo && cd ~/compose-demo
mkdir app
nano app/index.html
  • This file contains the content to be served by Nginx.


<h1>Docker Compose Demo</h1>
<p>Bu sayfa Nginx konteynerinden geliyor.</p>

docker-compose.yml Example


services:
web:
image: nginx:alpine
ports:
- "8000:80"
volumes:
- ./app:/usr/share/nginx/html
  • This structure broadcasts Nginx on port 8000.

3. Step: Running Docker Compose

  1. This command starts all services in the background.

docker compose up -d

To see running services:


docker compose ps

4. Step: Basic Docker Compose Commands

  1. To view logs:

docker compose logs

To stop services:


docker compose stop

  • To delete the entire structure:

docker compose down

5. Step: Multi-Service Application (WordPress + MySQL)

  1. This structure is frequently used in real projects.

services:
db:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: guclu_sifre
MYSQL_DATABASE: wordpress

wordpress:
image: wordpress:latest
ports:
- "8001:80"
depends_on:
- db

volumes:
db_data:
  • This structure runs WordPress with MySQL.

6. Step: Service Scaling

  1. This command creates multiple copies of the same service.

docker compose up -d --scale web=3
  • Note: If there is a fixed port definition, there will be conflict.

7. Step: Docker-compose (v1) → docker compose (v2) Migration

1. docker-compose ❌ deprecated

2. docker compose ✅ is the current command

3. YAML files are compatible


Frequently Asked Questions (FAQ)

1. What does Docker Compose do? It manages multiple containers with a single file.

2. Is Docker Compose suitable for production? It is suitable for single server structures.

3. What causes the permission denied error? The user is not in the docker group.


sudo usermod -aG docker $USER

4. How to resolve port conflict? Change host port.

5. Why does docker-compose.yml give an error? YAML indentation is incorrect.


Result

Docker Compose is the most practical way to manage modern applications. You start, stop and scale services with a single command.

🚀 You can publish your projects in minutes with Docker Compose on the GenixNode infrastructure.