⚠
Two updates since the original article: (1) CentOS 8 reached end-of-life on 31 December 2021 – use AlmaLinux 9, Rocky Linux 9, or CentOS Stream. (2) Docker Compose v1 (the docker-compose command) is deprecated. Compose v2 is now a Docker plugin, run as docker compose (with a space). The steps below use the current approach.
Docker Compose lets you define and run multi-container applications from a single YAML file – one command brings up your whole stack (app, database, cache) with the right networks and volumes. Compose is now built into Docker as a plugin (v2), so you install it alongside Docker itself. Here is the current setup for AlmaLinux 9, Rocky Linux 9, and CentOS Stream.
Step 1: Add the Docker Repository
sudo dnf install -y dnf-plugins-core sudo dnf config-manager --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
Step 2: Install Docker and the Compose Plugin
The docker-compose-plugin package provides Compose v2:
sudo dnf install -y docker-ce docker-ce-cli containerd.io \ docker-buildx-plugin docker-compose-plugin
Step 3: Start Docker and Verify
sudo systemctl enable --now docker docker --version docker compose version
Note the command is docker compose (with a space) for v2, not the old docker-compose. To run Docker without sudo, add your user to the docker group: sudo usermod -aG docker $USER, then log out and back in.
Step 4: A Sample docker-compose.yml
Create a file named docker-compose.yml – here’s a simple WordPress + MySQL stack:
services: db: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: change_me MYSQL_DATABASE: wordpress volumes: - db_data:/var/lib/mysql wordpress: image: wordpress:latest depends_on: - db ports: - "8080:80" environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_NAME: wordpress volumes: db_data:
Step 5: Key Compose Commands
docker compose up -d # start the stack in the background docker compose ps # list running services docker compose logs -f # follow logs docker compose down # stop and remove containers docker compose pull # update images
The modern Compose file no longer needs the version: line that older tutorials show – Compose v2 ignores it. Docker Compose runs well on any VPS or dedicated server; for production stacks, NVMe storage and guaranteed RAM make a noticeable difference.