A database used only by other containers
leave out host port publishing.
Practical VPS tutorial
Install Docker Engine and Compose on Ubuntu VPS from the official apt repository, run a private test container and check Docker ports before deploying apps.
I'd install Docker from its official apt repository on an Ubuntu VPS. You get Engine, the Compose plugin and a straightforward update path through apt. You don't need Docker Desktop on a server.

We'll finish by running a small web container on localhost. That checks the installation and networking before you add an application with real data.
This guide targets a fresh 64-bit Ubuntu 22.04, 24.04 or 26.04 LTS server. Check your release and architecture:
. /etc/os-release
printf '%s %s\n' "$PRETTY_NAME" "$(dpkg --print-architecture)"Docker's installation page lists supported releases and architectures. Use an account with sudo access and keep SSH recovery available.
You don't need a particular RAM size just to install Docker. Buy for the apps: 2 vCPU, 4 GB RAM and 40 GB SSD is a reasonable starting estimate for a small app plus database, not a Docker minimum.

Ubuntu's Docker packages and Docker's own packages have different names. Mixing them is an avoidable headache. Remove installed conflicts, then install the tools needed to add the official repository:
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)
sudo apt update
sudo apt install -y ca-certificates curlOn a clean VPS, messages about packages not being installed are normal. Package removal doesn't automatically erase Docker data, but it can interrupt existing containers.
This block installs the signing key and creates a repository entry for your Ubuntu release:
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
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt updateIf apt reports duplicate Docker sources, check whether you already have a docker.list entry. Keep one correct entry rather than adding the same repository twice.
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
sudo docker run --rm hello-world
sudo docker compose version
sudo systemctl is-active dockerLook for the hello-world success message, a Compose version and an active service result. The test container exits afterward; it isn't supposed to stay running.
Use docker compose, with a space. You don't need to install the older standalone docker-compose command for this guide.
The commands use sudo docker throughout. That keeps the permission model explicit. Adding your account to the docker group is optional and grants root-level host control through the Docker socket, as the post-installation guide explains.
Let's check something you can actually open. Create a separate test project and bind its web port to localhost:
sudo install -d -m 0755 /opt/docker-smoke
cd /opt/docker-smoke
sudo tee compose.yml > /dev/null <<'EOF'
services:
web:
image: nginx:alpine
ports:
- "127.0.0.1:8080:80"
logging:
driver: local
EOF
sudo docker compose up -d
sudo docker compose ps
curl --fail --head http://127.0.0.1:8080
sudo docker compose downThe HTTP check should return 200 OK. The final down command removes this test project's container and network, leaving its Compose file behind. If the first request arrives before Nginx is ready, wait a moment and repeat the curl check.
Port 8080 already in use? Change the left side of 127.0.0.1:8080:80, then use that port in the curl URL too. The right-hand 80 is Nginx's port inside the container.
Here's the detail I'd check before calling the server ready: Docker-published ports can bypass UFW rules. A database mapped as 5432:5432 may be reachable even when you expected the host firewall to block it. See Docker's firewall documentation.
leave out host port publishing.
bind the app to 127.0.0.1.
use a shared container network.
permission deniedUse sudo; don't make the socket world-writable.sudo systemctl status docker and sudo journalctl -u docker -n 50.sudo docker system df and logs before removing anything. Volumes may hold live data.Yes, but the application determines whether the server is large enough. A simple web container and a database-plus-browser stack have very different memory needs.
Your account lacks access to the Docker socket. Keeping sudo is fine. Group membership or rootless Docker are deliberate alternatives, not reasons to loosen socket permissions.
Ordinary down removes the project's containers and networks. Adding -v also removes applicable volumes, so don't use it casually on a live application.
Next step
Commands assume a fresh Ubuntu server. Replace domains, users, database names and provider-specific values before running them. VPS sizing is a practical starting point, not a guarantee: monitor the real workload and resize when CPU, memory, disk or network headroom becomes tight.
Affiliate links: you pay the same price as buying direct.