VPS

What is Docker Compose on VPS?
Run Multi-Container Apps with Ease

Updated September 14, 2026 · 12 min read

Docker Compose on VPS running multi-container applications

What is Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. Instead of typing multiple lengthy docker run commands for each container, you write a single docker-compose.yml file and start everything with one command: docker compose up.

For example, a typical web application consists of three parts: a web server, an application server, and a database. Docker Compose lets all three services work together without manually configuring the network for each one.

💡 Docker Compose is part of the Docker ecosystem. Since Docker v20.10, Compose v2 is bundled as a standard plugin — no separate installation required.

Docker vs Docker Compose

Beginners often confuse the two. Here's a clear comparison:

FeatureDockerDocker Compose
ManagesSingle containerMultiple containers simultaneously
Main commanddocker rundocker compose up
Config fileDockerfiledocker-compose.yml
NetworkingManual flagsAuto-created network
Best forSingle service, CI/CDMulti-service apps, Dev/Prod
Dependency orderNoneSupported via depends_on

Installing Docker + Compose on Ubuntu VPS

For VPS running Ubuntu 22.04 or 24.04, follow these steps:

Step 1: Update packages and install dependencies

sudo apt update && sudo apt upgrade -y
sudo apt install -y ca-certificates curl gnupg lsb-release

Step 2: Add Docker GPG key and repository

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 3: Install Docker Engine + Compose plugin

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io \
  docker-buildx-plugin docker-compose-plugin

Step 4: Add user to docker group

sudo usermod -aG docker $USER
newgrp docker

Verify installation

docker --version
docker compose version

⚠️ If docker compose (v2) is not found, verify that docker-compose-plugin is installed — don't confuse it with docker-compose (v1, hyphenated, deprecated).

docker-compose.yml File Structure

The docker-compose.yml file uses YAML format with three main sections:

services:          # Define each container
  web:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./html:/usr/share/nginx/html
    depends_on:
      - app

  app:
    build: .
    environment:
      - DB_HOST=db
    networks:
      - backend

  db:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: secret
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - backend

volumes:           # Define named volumes
  db_data:

networks:          # Define custom networks
  backend:
KeyDescription
servicesAll containers in the stack
imageDocker image to use
buildBuild from Dockerfile
portsMap host:container ports
volumesMount files/directories
environmentSet environment variables
depends_onStart after another service
networksAssign to a network
restartAuto-restart policy

Example: WordPress + MySQL on VPS

This is one of the most common Docker Compose use cases — running WordPress with a MySQL database:

version: '3.9'

services:
  wordpress:
    image: wordpress:latest
    ports:
      - "8080:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html
    depends_on:
      - db

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql

volumes:
  wp_data:
  db_data:

Save as docker-compose.yml and run:

docker compose up -d
docker compose ps   # Check status

Common Commands

CommandDescription
docker compose up -dStart all services (detached)
docker compose downStop and remove containers
docker compose down -vStop and remove containers + volumes
docker compose psShow status of all services
docker compose logs -fStream real-time logs
docker compose logs webShow logs for service "web"
docker compose exec app bashOpen shell inside container
docker compose restart dbRestart service "db" only
docker compose pullPull latest images
docker compose build --no-cacheRebuild images fresh

Networking and Volumes

Networking

When you run docker compose up, Docker automatically creates a default network named <foldername>_default. Every service can communicate with others using their service name as the hostname — so a service named db is reachable at hostname db from any other container in the same stack.

Volume Types

TypeExampleBest for
Named volumedb_data:/var/lib/mysqlDatabases, persistent data
Bind mount./src:/app/srcDevelopment, hot reload
Anonymous volume/tmp/cacheTemporary data

Managing Environment Variables with .env

Sensitive values like passwords should be stored in a separate .env file:

# .env
DB_PASSWORD=myS3cur3P@ss
MYSQL_ROOT_PASSWORD=r00tS3cr3t

Docker Compose automatically loads .env when it's in the same directory, and ${DB_PASSWORD} in the YAML is replaced with the actual value.

🔒 Always add .env to your .gitignore before committing to prevent credential leaks.

Production Tips for VPS

📌 AsiaGB VPS features SSD storage and 99% uptime — ideal for running Docker Compose stacks in production. Choose from Thailand (BKK) or Singapore VPS at asiagb.com/vps.html

Frequently Asked Questions

What is the difference between Docker and Docker Compose?
Docker manages individual containers using docker run. Docker Compose lets you define and run multi-container applications using a single YAML file, making service orchestration much simpler.
What VPS specs do I need for Docker Compose?
At least 2 GB RAM for lightweight stacks like WordPress + MySQL, and 4 GB or more for complex applications. 2 vCPU and SSD storage handles most typical workloads well.
What is the difference between Docker Compose v1 and v2?
Compose v1 uses docker-compose (Python-based, deprecated). Compose v2 is a Docker CLI plugin using docker compose (no hyphen), offering better performance and support for the latest Compose Specification.
Will my data be lost when I stop containers?
No, as long as you use volumes. When you run docker compose up again, volumes are remounted and your database data persists. Only docker compose down -v deletes volumes.
Can I use Docker Compose on AsiaGB VPS?
Yes. AsiaGB VPS runs Ubuntu and other Linux distributions, fully supporting Docker and Docker Compose. Both Thailand and Singapore VPS options are available with SSD storage and 99% uptime.
What does docker compose up -d mean?
The -d flag means detached mode — containers run in the background without printing logs to the terminal, leaving the shell free for other commands.

Summary

Docker Compose is an essential tool for developers who want to run multi-container apps on a VPS in an organized, repeatable way. Key benefits include:

  • Define your entire stack in one YAML file — great for team collaboration
  • Automatic network creation — services communicate by name
  • Easy volume management — data persists across restarts
  • One command docker compose up -d starts everything

Get started with AsiaGB VPS featuring SSD storage and 99% uptime — suitable for Docker Compose stacks from development to production.