Docker on a VPS: clean install, safe ports and a disk that stays free

A Docker VPS is an ordinary Linux server with Docker Engine on it: pick Ubuntu 24.04 or Debian 12, add Docker's own apt repository, and you have the same environment as on your laptop. For a few small containers start with 2 GB of RAM; for an application plus a database take 4 GB.

Updated: · Prices in the text are with the public IP (₼10 a month) unless stated otherwise.

How much server a container host needs

Docker itself is light. The containers decide the size, and building images needs far more than running them. These are starting points, not guarantees:

What you runRAMDiskPlan
2–4 small services, images built elsewhere2 GB40 GBBasic
App, database, cache and proxy4 GB60 GBStandard
Several projects, or builds on the server8 GB100 GBProfessional
  • Basic₼27.90/mo

    2 vCPU · 2 GB RAM · 40 GB NVMe

    Public IP +₼10/mo, With public IP: ₼37.90/mo

  • Standard₼39.90/mo

    2 vCPU · 4 GB RAM · 60 GB NVMe

    Public IP +₼10/mo, With public IP: ₼49.90/mo

  • Professional₼73.90/mo

    4 vCPU · 8 GB RAM · 100 GB NVMe

    Public IP +₼10/mo, With public IP: ₼83.90/mo

Prices in manat (AZN), billed monthly. The public IP is +₼10 a month and is assigned automatically.

The smallest plan (1 vCPU, 1 GB RAM, 30 GB NVMe) runs one container well, but image layers fill 30 GB quickly. Standard is ₼49.90 a month. If 4 GB of RAM is enough but 60 GB of disk is not, Plus (4 vCPU, 4 GB RAM, 80 GB NVMe) is ₼65.90; for 100 GB of disk the smallest plan is Professional at ₼83.90. These prices are with public IP (₼10 a month of each), so the server can pull images and answer on 80 and 443 from the start.

Install Docker from the official repository

Use Docker's repository rather than the docker.io or snap package, so that Engine, Buildx and Compose come from one source and update with apt. The commands work on Ubuntu 24.04, Ubuntu 22.04 and Debian 12:

# Remove older packages, if any
sudo apt remove -y docker.io docker-compose podman-docker containerd runc 2>/dev/null

sudo apt update && sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
. /etc/os-release
sudo curl -fsSL "https://download.docker.com/linux/$ID/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 <<END
Types: deb
URIs: https://download.docker.com/linux/$ID
Suites: $VERSION_CODENAME
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
END

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run --rm hello-world

Adding a user to the docker group removes the need for sudo, but membership is equal to root access. Give it only to people you would give root to.

A Compose file worth copying

This example runs Uptime Kuma, a monitoring page. The habits matter more than the app: a fixed major version, a named volume, a memory limit, a restart policy and a port bound to localhost.

# /opt/kuma/compose.yaml
services:
  kuma:
    image: louislam/uptime-kuma:2
    restart: unless-stopped
    mem_limit: 512m
    ports:
      - "127.0.0.1:3001:3001"
    volumes:
      - kuma-data:/app/data

volumes:
  kuma-data:
cd /opt/kuma
sudo docker compose up -d
sudo docker compose logs -f --tail=50
# later: update
sudo docker compose pull && sudo docker compose up -d

Put nginx on the host in front of it and give it a certificate; the nginx and SSL guide has the server block. Keep passwords in a .env file with mode 600 next to the Compose file, and out of Git.

Why ufw does not protect published ports

Docker writes its own packet-filter rules, and traffic to a published port is forwarded to the container before ufw's input rules see it. ufw deny 5432 therefore does nothing for a database started with -p 5432:5432: it is open to the internet.

Written in ComposeReachable from
"5432:5432"Anywhere, whatever ufw says
"127.0.0.1:5432:5432"Only the server itself
no ports at allOnly containers on the same Docker network

The rule is short: databases and caches get no ports, web apps get 127.0.0.1, and only the reverse proxy listens on 80 and 443. If a port must be public for one address, filter it in the DOCKER-USER chain, which Docker leaves to you:

# Replace eth0 with your interface (ip route show default)
sudo iptables -I DOCKER-USER -i eth0 -p tcp -m conntrack \
  --ctorigdstport 8080 --ctdir ORIGINAL ! -s 203.0.113.10 -j DROP

That rule disappears at reboot unless you save it, so binding to localhost is the better default. Check from another computer with nc -zv SERVER_IP 5432; testing on the server proves nothing. The rest of the hardening list is in securing a VPS.

Stop logs and old images from filling the disk

By default the json-file log driver has no size limit, so one noisy container can fill the disk and stop everything else. Set a limit in /etc/docker/daemon.json:

{
  "log-driver": "local",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}

Run sudo systemctl restart docker, then recreate containers with docker compose up -d --force-recreate; existing ones keep their old settings. For images:

sudo docker system df                                  # what uses space
sudo docker system prune -af --filter "until=168h"     # unused, older than 7 days

That prune removes stopped containers and unused images but not volumes. Never add --volumes to a scheduled job: a stopped database can lose its data that way.

VPS with Docker or managed containers?

QuestionDocker on your VPSManaged containers
Who patches the operating system?YouThe provider
Root access and host settingsYesNo
Several Compose projects on one priceYesUsually sized per container
Person on your side who knows LinuxRequiredNot required

Choose a VPS when you want cron jobs, a VPN and databases beside the containers. Choose managed containers when you have an image to run and nobody to maintain a server. Unmanaged plans and sizes are listed on the pricing page.

Docker VPS questions

Can I run Docker on a 1 GB VPS?

Yes, for one or two light containers. Build images on your own computer or in CI, set memory limits, and do not expect a database and a web app to share 1 GB comfortably.

Does Docker Compose need a separate install?

No. The docker-compose-plugin package gives you the "docker compose" command. The old "docker-compose" program with a hyphen is no longer needed.

Why is my container open although ufw is enabled?

Because published ports are forwarded by Docker's own rules, not by the input chain ufw controls. Bind the port to 127.0.0.1 or remove the ports section.

Can I use Docker on a Windows VPS?

Use a Linux server for Linux containers. Docker Desktop depends on nested virtualisation, which you should not assume is available on a Windows VPS.

Is Docker preinstalled at Cloudraft?

No. You receive a clean Ubuntu, Debian or Windows Server system with full access and install Docker yourself with the commands above.

Read next

All VPS pages

This page in other languages: Русский · Türkçe

Servers in Baku, prices in manat

Create an account, top up your balance and order the plan you need.