How to Install Docker Compose on RHEL 7
Docker Compose is a tool for defining and running multi-container applications using a single YAML configuration file. Rather than issuing long docker run commands manually for each service, you describe your entire application stack — web server, database, cache, and more — in a docker-compose.yml file and manage it with a handful of commands. This tutorial covers the two main installation methods (the Docker Compose plugin v2 and the standalone v1 binary), explains how to write a basic Compose file, and demonstrates the most important day-to-day commands on RHEL 7.
Prerequisites
- Docker CE installed and running on RHEL 7 (see the Docker Engine installation tutorial)
- Root or sudo access to the system
- Internet connectivity to download the Compose binary from GitHub or Docker
- Familiarity with basic Docker concepts: images, containers, and volumes
Step 1: Understand Docker Compose v1 vs v2
There are two distinct versions of Docker Compose in common use, and it is important to understand the difference before installing.
Docker Compose v1 (standalone binary)
The original Docker Compose was written in Python and distributed as a standalone binary named docker-compose (with a hyphen). It is invoked as a separate command and is not integrated into the docker CLI. Version 1.x reached end-of-life in July 2023, but it remains widely used on older systems because it has no dependency on a modern Docker CLI.
Docker Compose v2 (Docker CLI plugin)
Docker Compose v2 was rewritten in Go and integrated directly into the Docker CLI as a plugin. It is invoked as docker compose (no hyphen). It is faster, supports additional Compose file specification features, and is the current actively maintained version. For new projects on RHEL 7, v2 is strongly recommended.
Step 2: Install Docker Compose v2 as a CLI Plugin
The recommended installation method for Docker Compose v2 is through the Docker CLI plugin mechanism. Create the plugin directory and download the binary:
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64
-o $DOCKER_CONFIG/cli-plugins/docker-compose
Make the binary executable:
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
Verify the installation:
docker compose version
Expected output:
Docker Compose version v2.24.5
To install the plugin system-wide (available to all users), place the binary in /usr/local/lib/docker/cli-plugins/ instead:
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64
-o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
Step 3: Install Docker Compose v1 Standalone Binary (Alternative)
If you need the legacy docker-compose v1 binary for compatibility with older scripts or CI pipelines, download it directly from GitHub Releases.
First, check the latest v1 release at https://github.com/docker/compose/releases. The final v1 release was 1.29.2:
sudo curl -L
"https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)"
-o /usr/local/bin/docker-compose
Make the binary executable:
sudo chmod +x /usr/local/bin/docker-compose
Confirm the installation:
docker-compose --version
Expected output:
docker-compose version 1.29.2, build 5becea4c
If you want both v1 and v2 available simultaneously, name the v1 binary differently or manage them via alternatives:
sudo ln -s /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v1
Step 4: Verify Compose Can Connect to Docker
Run a quick sanity check to confirm Compose can communicate with the Docker daemon:
# v2
docker compose ls
# v1
docker-compose ps
If you receive a permission error, ensure your user is in the docker group (see the Docker Engine tutorial) and that you have logged out and back in to apply the group change.
Step 5: Write a Basic docker-compose.yml File
Compose files use YAML syntax. Create a working directory and a basic example that runs an Nginx web server alongside a Redis cache:
mkdir -p ~/compose-demo
cd ~/compose-demo
cat > docker-compose.yml <<'EOF'
version: "3.9"
services:
web:
image: nginx:1.25-alpine
container_name: demo_web
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html:ro
depends_on:
- cache
restart: unless-stopped
cache:
image: redis:7-alpine
container_name: demo_cache
ports:
- "6379:6379"
volumes:
- redis_data:/data
restart: unless-stopped
volumes:
redis_data:
EOF
Create a simple HTML file for Nginx to serve:
mkdir -p html
echo "<h1>Hello from Docker Compose on RHEL 7</h1>" > html/index.html
Step 6: Run the Application Stack
Start the stack in detached (background) mode:
# v2
docker compose up -d
# v1
docker-compose up -d
Docker Compose will pull the required images (if not already cached), create the defined network, create the named volume, and start both containers. Output looks similar to:
[+] Running 3/3
✔ Network compose-demo_default Created
✔ Container demo_cache Started
✔ Container demo_web Started
Step 7: Inspect Running Services
List the running services and their status:
docker compose ps
View real-time logs from all services (or a specific service):
# All services
docker compose logs -f
# Only the web service
docker compose logs -f web
Step 8: Stop and Clean Up
Stop the running containers without removing them:
docker compose stop
Stop and remove containers, networks, and the default volumes:
docker compose down
To also remove named volumes (such as redis_data), use the -v flag:
docker compose down -v
Conclusion
You now have Docker Compose installed on RHEL 7 and understand the difference between the modern v2 plugin (invoked as docker compose) and the legacy v1 standalone binary (docker-compose). With a single docker-compose.yml file you can define complex multi-service applications, manage their lifecycle with straightforward commands, and reproduce the same environment consistently across development and production. As you build more complex stacks, explore advanced Compose features such as environment variable substitution (.env files), health checks, build contexts, and Compose profiles for selectively starting service subsets.