
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
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:
- Image — A read-only template (blueprint) for creating containers
- Container — A running instance of an image
- Registry — A repository for images (e.g., Docker Hub)
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 Problem | How Docker Solves It |
|---|---|
| Dependency conflicts between apps | Each container has a completely isolated environment |
| Complex deployment procedures | Deploy with docker run or docker compose up |
| Difficult to scale | Spin up new containers in under 10 seconds |
| "Works on my machine" syndrome | Identical environment across all stages |
| Painful rollbacks | Switch image versions instantly |
System Requirements
Before installing Docker, verify your VPS meets these specifications:
| Component | Minimum | Recommended |
|---|---|---|
| OS | Ubuntu 20.04 LTS | Ubuntu 22.04 LTS or newer |
| RAM | 1 GB | 2 GB or more |
| Storage (SSD) | 10 GB free | 20 GB or more |
| CPU | 1 vCore | 2 vCores or more |
| Access | SSH with sudo | Non-root sudo user |
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
docker --version and docker compose version to confirm.
Essential Docker Commands
The most frequently used Docker commands:
| Command | Purpose | Example |
|---|---|---|
docker pull | Download image from registry | docker pull nginx:latest |
docker run | Create and run a container | docker run -d -p 80:80 nginx |
docker ps | List running containers | docker ps -a (show all) |
docker stop | Stop a container | docker stop my-container |
docker rm | Remove a container | docker rm my-container |
docker images | List all images | docker images |
docker exec | Run command inside running container | docker exec -it my-nginx bash |
docker logs | View container logs | docker 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:
- Web Applications: Deploy Node.js, Python Flask, PHP Laravel in minutes
- Databases: Run MySQL, PostgreSQL, MongoDB without affecting the host system
- CI/CD: GitLab Runner or Jenkins in a container for automated pipelines
- Reverse Proxy: Nginx or Traefik to route multiple apps on one VPS
- Game Servers: Minecraft, Valheim servers in isolated containers
- Monitoring: Prometheus + Grafana stack deployed in 2 commands
Docker Security on VPS
Docker enhances isolation, but there are key security practices to follow:
- Never run containers as root: Use the
--userflag or define a non-root user in your Dockerfile - Use official images: Only pull from Docker Hub Official or Verified Publisher images
- Update images regularly: Run
docker pull <image>frequently to get security patches - Limit resources: Use
--memoryand--cpusto prevent resource exhaustion - Firewall awareness: Docker bypasses UFW by default — configure rules carefully
# 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