Ubuntu VPS Docker Setup: Install Docker + Compose the Right Way
If you are deploying applications, reliable containerization is essential. However, installing Docker from the default Ubuntu repositories often leaves you with outdated versions that lack critical features. This tutorial covers the modern and official way for Ubuntu VPS Docker setup and also includes Docker Compose installation.
This guide ensures your containers run smoothly, which makes it the perfect setup for a high-performance Linux VPS from Perlod Hosting.
Table of Contents
Prerequisites for Ubuntu VPS Docker Setup
In this guide, we assume you have an Ubuntu VPS, Ubuntu 22.04, or Ubuntu 24.04. If you are looking for a reliable provider, a high-performance Linux VPS is recommended for production workloads.
Also, you must have SSH access to your server and a user with sudo privileges.
Now, proceed to the following steps to start the Ubuntu VPS Docker setup.
1. Update and Prepare the System
Update your local package index, which prevents conflicts during installation:
sudo apt update && sudo apt upgrade -y
Install the necessary prerequisite packages that allow apt to use packages over HTTPS with the command below:
sudo apt install ca-certificates curl gnupg -y
2. Add Docker’s Official GPG Key
For Ubuntu VPS Docker setup, you must add Docker’s official GPG key to a dedicated keyring.
Create the directory for the key with the command below:
sudo install -m 0755 -d /etc/apt/keyrings
Download the key and give it the proper permission with the commands below:
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
3. Add the Docker Repository
Once you are done with the GPG key, you can add the Docker repository to your system’s source list. To do this, you can use the following command, which automatically detects your Ubuntu version and CPU architecture:
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
Run the system update again so it sees the new Docker packages:
sudo apt update
4. Install Docker and Docker Compose Plugin
In the past, you might have installed a separate binary for Docker Compose. Today, the standard is the Docker Compose Plugin, which integrates directly into the Docker CLI.
To install Docker and Docker Compose on your Ubuntu VPS, run the command below:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Explanation:
- docker-ce: The Docker CE engine.
- docker-ce-cli: The command-line interface you type into.
- containerd.io: The container runtime that manages the container lifecycle.
- docker-compose-plugin: Enables the docker compose command.
Note: By default, Docker commands require sudo. This can be a security risk if scripts rely on root. To fix this, add your current user to the Docker group with the command below:
sudo usermod -aG docker $USER
To apply the changes, you can log out and log in again, or you can activate the group change immediately with this command:
newgrp docker
To confirm everything is working correctly, check your Docker and Docker Compose versions:
docker --version
Output:
Docker version 29.2.1, build a5c7197
docker compose version
Output:
Docker Compose version v5.0.2
Note: The command is docker compose, not docker-compose.
Also, you can run a test container with:
docker run hello-world
If you see a message Hello from Docker, your installation is successful.
Hello from Docker!
This message shows that your installation appears to be working correctly.
Configure Log Rotation for Docker Setup in VPS
For a production Ubuntu VPS Docker setup, unlimited logs can fill your disk space. It is best practice to configure log rotation.
You can create or edit the daemon configuration file with your desired text editor:
sudo nano /etc/docker/daemon.json
Add the following configuration to the file:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Once you are done, restart Docker to apply the changes:
sudo systemctl restart docker
This limits logs to 10MB per file and keeps only the last 3 files.
FAQs
What is the difference between docker compose and docker-compose?
The docker-compose command is an outdated and deprecated tool. The docker compose command is the modern and faster standard built directly into Docker.
Why am I getting a permission denied error when running Docker commands?
Because you are trying to run Docker without sudo, but your user doesn’t have the necessary permissions. Run sudo usermod -aG docker $USER to resolve it and apply it by logging out and logging back in.
Can I use Snap to install Docker on an Ubuntu VPS?
It is recommended to use the apt repository, which installs standard files exactly where they belong on your server. Snap creates complex permission issues and clutters your system with unnecessary virtual drives.
Conclusion
You have successfully installed the Docker Engine and the Docker Compose plugin using the official repository method. This setup ensures your infrastructure is running the latest stable release with all critical security patches applied. With your environment properly configured and log rotation enabled, your server is now ready for production workloads. Whether you are deploying databases, web apps, or AI models, this foundation ensures your Linux VPS operates efficiently.
We hope you enjoy this guide. Subscribe to our X and Facebook channels to get the latest articles.
For further reading: