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.
If you want a server prepared for container workloads, you can deploy a Docker VPS with full root access and NVMe storage.
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}
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}
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 Use a 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.
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.
