Install Docker on Ubuntu VPS

Install and Use Docker on Ubuntu VPS — Beginner's Guide

Docker is the world's most popular containerization platform. Running Docker on a VPS lets you deploy applications in seconds, scale effortlessly, and maintain consistent environments from development to production. This guide walks you through everything from installation to real-world usage.

Table of Contents

  1. What is Docker?
  2. Why Use Docker on VPS?
  3. System Requirements
  4. Installing Docker on Ubuntu
  5. Essential Docker Commands
  6. Docker Compose — Multi-Container Management
  7. Real-World Use Cases
  8. Docker Security on VPS
  9. Frequently Asked Questions
  10. Summary

What is Docker?

Docker is an open-source platform for building, shipping, and running applications inside containers — lightweight, isolated environments that package your application with all its dependencies.

Three core concepts:

💡 Analogy: An Image is like a class in OOP; a Container is like an object instantiated from that class.

Why Use Docker on VPS?

Traditional VPS app deployment faces issues like dependency conflicts, slow scaling, and environment inconsistency. Docker solves all of them:

Traditional ProblemHow Docker Solves It
Dependency conflicts between appsEach container has a completely isolated environment
Complex deployment proceduresDeploy with docker run or docker compose up
Difficult to scaleSpin up new containers in under 10 seconds
"Works on my machine" syndromeIdentical environment across all stages
Painful rollbacksSwitch image versions instantly

System Requirements

Before installing Docker, verify your VPS meets these specifications:

ComponentMinimumRecommended
OSUbuntu 20.04 LTSUbuntu 22.04 LTS or newer
RAM1 GB2 GB or more
Storage (SSD)10 GB free20 GB or more
CPU1 vCore2 vCores or more
AccessSSH with sudoNon-root sudo user
⚠️ Note: AsiaGB VPS uses SSD storage on all plans — ideal for Docker workloads requiring fast I/O.

Installing Docker on Ubuntu

Method 1: Install via apt (Easiest)

# 1. Update package list
sudo apt update

# 2. Install Docker
sudo apt install -y docker.io

# 3. Enable and start Docker
sudo systemctl enable --now docker

# 4. Verify Docker is running
sudo systemctl status docker

# 5. Add your user to the docker group (avoid sudo every time)
sudo usermod -aG docker $USER

# 6. Log out, log back in, then test
docker run hello-world

Method 2: Install Docker CE (Latest Version)

# Install dependencies
sudo apt install -y ca-certificates curl gnupg

# Add Docker GPG key
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
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list

# Install Docker CE
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
✅ Verify installation: Run docker --version and docker compose version to confirm.

Essential Docker Commands

The most frequently used Docker commands:

CommandPurposeExample
docker pullDownload image from registrydocker pull nginx:latest
docker runCreate and run a containerdocker run -d -p 80:80 nginx
docker psList running containersdocker ps -a (show all)
docker stopStop a containerdocker stop my-container
docker rmRemove a containerdocker rm my-container
docker imagesList all imagesdocker images
docker execRun command inside running containerdocker exec -it my-nginx bash
docker logsView container logsdocker logs -f my-container

Quick Example: Run an Nginx Web Server

# Run Nginx on port 8080
docker run -d --name my-nginx -p 8080:80 nginx:alpine

# Test it
curl http://localhost:8080

# View logs
docker logs my-nginx

# Stop and remove
docker stop my-nginx && docker rm my-nginx

Docker Compose — Multi-Container Management

Docker Compose lets you define and manage multi-container applications in a single docker-compose.yml file.

Example: WordPress + MySQL + Redis Stack

version: '3.8'
services:
  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: wordpress
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: always
    depends_on:
      - db
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: secret

  redis:
    image: redis:alpine
    restart: always

volumes:
  db_data:

Start with docker compose up -d and stop with docker compose down.

Real-World Use Cases

Docker on VPS is ideal for a wide range of workloads:

💡 Pro Tip: AsiaGB Thailand VPS (Bangkok) with 99% uptime is perfect for running Docker web services that need low latency for Thai users.

Docker Security on VPS

Docker enhances isolation, but there are key security practices to follow:

# Limit memory and CPU
docker run -d --name my-app --memory="512m" --cpus="0.5" my-image

# Fix Docker bypassing UFW
# Edit /etc/default/ufw: DEFAULT_FORWARD_POLICY="ACCEPT"
sudo ufw reload

Frequently Asked Questions

What VPS specs do I need for Docker?

For basic Docker usage, 1 GB RAM and 1 vCPU is the minimum. For multiple containers, 2 GB RAM or more is recommended.

What is the difference between Docker and a Virtual Machine?

Docker containers share the host kernel, making them 10–20x lighter than VMs. VMs run a full OS and consume significantly more resources.

What is Docker Compose?

Docker Compose manages multiple containers using a docker-compose.yml file. It's ideal for multi-service apps like Web + Database + Cache.

How do I install Docker on Ubuntu?

Run: sudo apt update && sudo apt install -y docker.io && sudo systemctl enable --now docker, then add your user: sudo usermod -aG docker $USER.

What is the difference between a Docker Image and a Container?

An Image is a blueprint; a Container is a running instance of that blueprint. One image can create multiple containers simultaneously.

Summary

Docker on Ubuntu VPS opens up a world of fast, flexible, and manageable application deployment. With a simple apt install docker.io, you're ready to run containers in minutes.

In this guide you learned: Docker installation, essential commands, Docker Compose for multi-container apps, real-world use cases, and security best practices.

Need a VPS for Docker?

AsiaGB Thailand VPS — SSD Storage, 99% Uptime, DirectAdmin control panel. Starting at ฿500/month.

View Thailand VPS Plans