How to Install Docker Compose on Ubuntu VPS

Docker Compose allows you to define and manage multi-container applications using a single YAML configuration file. It is widely used for deploying web applications, databases, APIs, and development environments on a Linux VPS.

Requirements

  • Ubuntu VPS (22.04 or 24.04)
  • Docker Engine installed
  • SSH access with sudo privileges

Step 1 — Verify Docker Installation

docker --version

If Docker is not installed yet, install Docker before continuing.

Step 2 — Verify Docker Compose Plugin

docker compose version

If Docker Compose is already installed, you will see the installed version.

Step 3 — Install Docker Compose

Update your package list first:

sudo apt update

Install the official Docker Compose plugin:

sudo apt install docker-compose-plugin -y

Step 4 — Verify Installation

docker compose version

Example output:

Docker Compose version v2.x.x

Step 5 — Create a Test Project

mkdir docker-test
cd docker-test

Create a new file named docker-compose.yml.

nano docker-compose.yml

Add the following configuration:

services:
  nginx:
    image: nginx:latest
    ports:
      - "80:80"

Save the file and exit.

Step 6 — Start the Container

docker compose up -d

Docker will automatically download the Nginx image and start the container.

Step 7 — Verify Running Containers

docker ps

You should see the Nginx container running.

Step 8 — Stop the Project

docker compose down

Useful Docker Compose Commands

docker compose up -d
docker compose down
docker compose restart
docker compose logs
docker compose ps
docker compose pull

Best Practices

  • Always use the latest stable Docker images.
  • Store application data in Docker volumes.
  • Keep your compose files under version control.
  • Use environment variables for sensitive information.
  • Regularly update Docker and Docker Compose.

Conclusion

Docker Compose makes deploying and managing multiple containers simple and efficient. It is an essential tool for developers, DevOps engineers, and anyone hosting applications on a VPS.


Related Articles

  • How to Install Docker on Ubuntu 24.04 VPS
  • How to Install Nginx on Ubuntu VPS
  • How to Install Node.js on Ubuntu VPS
  • How to Secure Your Linux VPS
  • How to Connect to Your VPS via SSH
  • Docker
  • 0 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

How to Change Your SSH Port for Better Security

By default, SSH runs on port 22, which is commonly targeted by automated attacks. Changing the...

How to Connect to Your VPS via SSH

SSH (Secure Shell) is a protocol used to securely connect to your VPS. Follow the steps below to...

How to Update and Upgrade Your VPS

Keeping your VPS up to date is essential for security and performance. Here’s how to update and...

How to Check Your VPS Resource Usage

Monitoring your VPS resource usage helps you keep your server performing well. Here’s how you can...

How to Reboot Your VPS Safely

<p>Sometimes, you need to reboot your VPS to apply updates or fix issues. Here’s how to do...