Docker lets you package applications and their dependencies into lightweight, portable containers that run identically on any Linux server. Deploying Docker on a VPS gives you the isolation of virtual machines without the overhead, making it ideal for hosting multiple web apps, APIs, or databases on a single server. This guide covers installing Docker on Ubuntu 24.04, running your first container, and securing the setup for production. Compare VPS plans on our site to find a provider with the resources to run multiple containers smoothly.
Prerequisites: Minimum VPS Specs for Docker
Docker itself is lightweight (the daemon uses ~100 MB RAM at idle), but your containers need memory too. For a typical setup hosting 3–5 containers:
| Component | Minimum | Recommended |
|---|---|---|
| CPU | 1 vCPU | 2 vCPU |
| RAM | 1 GB | 2–4 GB |
| Storage | 20 GB | 40 GB NVMe |
| OS | Ubuntu 22.04+ | Ubuntu 24.04 LTS |
Step 1: Install Docker Engine
Use the official Docker repository for the latest stable release. Do not use apt install docker.io — that version is often outdated:
# Remove old versions (if any)
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Add Docker's official GPG key
sudo apt-get update
sudo apt-get install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository
# Replace "noble" with your Ubuntu codename if different
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Install Docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Verify the installation: sudo docker run hello-world. If you see the Hello from Docker! message, everything is working.
Step 2: Run Docker Without Sudo (Post-Install)
By default, Docker requires sudo. Adding your user to the docker group eliminates this:
sudo usermod -aG docker $USER
# Log out and back in (or run: newgrp docker)
# Test:
docker run hello-world
Security note: The docker group grants root-equivalent privileges. On a multi-user VPS, consider using rootless Docker (Docker’s rootless mode) instead of the group approach.
Step 3: Deploy a Real Application with Docker Compose
Docker Compose lets you define multi-container applications in a YAML file. Here is a complete example that runs Nginx + PHP + MariaDB for a WordPress site:
# docker-compose.yml
version: '3.8'
services:
db:
image: mariadb:10.11
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: your_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wpuser
MYSQL_PASSWORD: wp_password
wordpress:
image: wordpress:latest
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wpuser
WORDPRESS_DB_PASSWORD: wp_password
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
volumes:
db_data:
wp_data:
Deploy with: docker compose up -d. Access WordPress at http://your-vps-ip:8080. Add a reverse proxy (Nginx on the host, or another container) to serve on port 443 with SSL.
Step 4: Secure Docker on Your VPS
- Limit container resources: Use
--memoryand--cpusflags to prevent a single container from exhausting the host. Example:docker run --memory=512m --cpus=0.5 nginx. - Use read-only root filesystem: Add
--read-onlyto containers that do not need write access to their filesystem. - Keep images updated: Run
docker pullregularly and rebuild containers when security patches are released. - Scan images for vulnerabilities:
docker scout quickview your-image(requires Docker Scout). - Never expose the Docker socket in a container unless absolutely required — it gives full host control.
Step 5: Enable Log Rotation
Container logs accumulate quickly and can fill your VPS disk. Configure log rotation globally by creating or editing /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Restart Docker: sudo systemctl restart docker. This limits each container to three 10 MB log files (30 MB max per container).
Docker transforms a general-purpose VPS into a flexible application platform. Once you have the basics running, explore Docker Swarm or Kubernetes for orchestration across multiple VPS nodes. For now, start with Compose — it handles the vast majority of single-server deployments without added complexity. Check out VPS plans on our site to find a provider that meets your container hosting needs.




Leave a Reply
You must be logged in to post a comment.