How to Install Docker on a VPS (Ubuntu and Debian)
Docker is one of the most popular ways to run applications in isolated containers. A VPS is a great fit for Docker because it gives you full root access, predictable resources, and the flexibility to run multiple services on the same server.
This guide shows how to install Docker Engine on a VPS running Ubuntu or Debian.
Before you start the manual process, remember: If you value your time, you can deploy a Docker VPS via the mvps.net panel with Docker and Docker Compose pre-installed and optimized for our NVMe infrastructure.
What You Need
- A VPS running a supported Ubuntu or Debian release
- Root access, or a user with
sudo - A 64-bit system
Docker provides separate installation instructions for Ubuntu, Debian, and RHEL-based systems, so this article focuses only on Ubuntu and Debian. :contentReference[oaicite:1]{index=1}
Shortcut: The One-Click Way
If you are starting a new project, you don’t need to run these commands manually. mvps.net offers a One-Click Docker App during the VPS provisioning process. It handles the GPG keys, repositories, and dependencies automatically.
Step 1: Connect to Your VPS
ssh root@YOUR_SERVER_IP
Replace YOUR_SERVER_IP with your VPS IP address.
Step 2: Remove Old or Conflicting Packages
Before installing Docker from the official repository, remove older or conflicting packages if they are present.
Ubuntu:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove -y $pkg; done
Debian:
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove -y $pkg; done
Docker recommends removing distribution-provided Docker packages before installing the official Docker Engine packages. :contentReference[oaicite:2]{index=2}
Step 3: Update the Package Index
sudo apt-get update
Step 4: Install Required Packages
sudo apt-get install -y ca-certificates curl
Step 5: Add Docker’s Official GPG Key
Ubuntu:
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
Debian:
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Step 6: Add the Docker Repository
Ubuntu:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Debian:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
These repository steps follow Docker’s current official installation method for apt-based systems. :contentReference[oaicite:3]{index=3}
Step 7: Install Docker Engine
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
This installs Docker Engine, the CLI, containerd, Buildx, and the Docker Compose plugin. :contentReference[oaicite:4]{index=4}
Step 8: Verify the Installation
sudo docker run hello-world
If Docker is installed correctly, the command downloads and runs a test container.
Optional: Start Docker Automatically on Boot
sudo systemctl enable docker
sudo systemctl enable containerd
Docker also documents Linux post-installation steps such as running Docker without root and enabling services on boot. :contentReference[oaicite:5]{index=5}
Step 9: Security Best Practices (UFW & Docker)
💡 Critical Security Tip: By default, Docker manipulates iptables directly, which can sometimes bypass your UFW firewall rules.
- Always check your exposed ports with
sudo ss -tulpn. - If you are using a high-security VPS, consider configuring Docker to respect UFW or use a Reverse Proxy like Nginx (in a container) to handle incoming traffic.
Running Your First Stack (Docker Compose)
Instead of running single containers, modern developers use Docker Compose (now integrated as docker compose without the hyphen). Try this simple docker-compose.yml to launch Nginx with persistent storage:
YAML
services:
web:
image: nginx:latest
ports:
- "80:80"
restart: always
Run it with: docker compose up -d.
Optional: Run Docker Without sudo
sudo usermod -aG docker $USER
Then log out and log back in for the group change to apply.
Run Your First Container
For example, to launch an Nginx container:
sudo docker run -d -p 80:80 --name nginx nginx
You can then open your VPS IP address in a browser and see the default Nginx page.
Why Choose an NVMe VPS for Docker?
- Full root access
- Isolation from other users
- Easy deployment of multiple apps
- Good fit for self-hosted tools and APIs
- Predictable CPU, RAM, and storage resources
A Docker VPS hosting setup is ideal for running web apps, APIs, CI tools, reverse proxies, and self-hosted services.
Docker containers rely heavily on the host’s disk performance, especially during docker build operations and when running database containers (like PostgreSQL or MongoDB).
- Faster Builds: NVMe drives reduce the time spent in the “Exporting layers” phase.
- Lower Latency: Database containers hosted on a high-performance VPS benefit from significantly lower I/O wait times compared to standard SSDs.
Conclusion
Installing Docker on Ubuntu or Debian is straightforward when you use Docker’s official repository. Once installed, you can deploy containers quickly and manage applications much more easily than on traditional shared hosting.
If you want a server optimized for containers, you can launch a Docker VPS and start deploying immediately.
