Skip to content
Wallet live · USDT TRC20 · USDT BEP20 · BTC · ETH · SOL · XMR Free SSL · Malware scan · Instant image 24/7 desk · @rexahost
RexaHostRexaHost

VPS

Docker on a VPS: A Practical Getting Started Guide

· 5 min read

Docker on a VPS: A Practical Getting Started Guide

Docker makes deploying apps on a VPS repeatable. Install Docker Engine, deploy with Compose, add HTTPS with a reverse proxy, and avoid the common security mistakes.

Key takeaways

  • Docker needs a KVM-based VPS with its own kernel; all RexaHost VPS plans qualify.
  • Install Docker Engine from the official repository, not outdated distribution packages.
  • Use Docker Compose to define your stack in one file.
  • Put a reverse proxy in front for HTTPS, and bind app ports to localhost.
  • Store data in volumes and back them up; containers themselves are disposable.

Docker packages an application and its dependencies into a container that runs the same way everywhere. On a VPS, that means you can deploy a web app, database, monitoring tool or self-hosted service in minutes, update it cleanly and move it to a new server without reinstalling everything by hand. This guide takes you from a fresh Linux VPS to a working, secure Docker setup.

Why Docker on a VPS?

  • Repeatable deployments: the same Compose file works on your laptop and your server.
  • Isolation: each service has its own dependencies, so a PHP app and a Node.js app do not conflict.
  • Easy updates and rollbacks: pull a new image, recreate the container, and roll back by pinning the old tag.
  • Portability: moving servers is mostly copying your Compose files and volumes.

Requirements

Use caseSuggested planSpecsPrice
Learning, one or two light containersVPS Starter1 vCPU / 1 GB / 25 GB NVMe$2.78
Small app plus reverse proxyVPS Basic1 vCPU / 2 GB / 60 GB NVMe$5.98
Web app plus database plus monitoringVPS Pro2 vCPU / 4 GB / 120 GB NVMe$11.58
Several apps or heavier stacksVPS Business4 vCPU / 8 GB / 240 GB NVMe$21.18

Docker requires its own kernel, which KVM provides. See KVM virtualisation explained for why this matters. Container images and logs use disk space quickly, so leave headroom.

Step 1: Prepare the server

Start with a fresh Ubuntu 24.04 or Debian 12 VPS. Create a sudo user, set up SSH keys, enable a firewall and apply updates. Our Linux VPS security checklist walks through these steps.

Step 2: Install Docker Engine

Install from Docker's official repository to get current versions and the Compose plugin. The convenience script is the quickest way:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo systemctl enable --now docker
docker --version
docker compose version

For production, many admins prefer to add the apt repository manually following Docker's documentation, so they can review each step. Either way, check the script before running it.

To run Docker without sudo, add your user to the docker group: sudo usermod -aG docker $USER, then log out and in. Be aware that membership of the docker group is effectively root access.

Step 3: Run your first container

docker run --rm hello-world

If you see the welcome message, Docker works. Clean up unused images later with docker image prune.

Step 4: Deploy a stack with Docker Compose

Create a project directory and a compose.yaml file. This example runs a web application with a PostgreSQL database:

services:
  app:
    image: ghcr.io/example/app:1.4.2
    restart: unless-stopped
    environment:
      DATABASE_URL: postgres://app:${DB_PASSWORD}@db:5432/app
    ports:
      - "127.0.0.1:8080:8080"
    depends_on:
      - db
  db:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: app
    volumes:
      - dbdata:/var/lib/postgresql/data
volumes:
  dbdata:

Put secrets in a .env file next to it (and keep that file out of version control), then start the stack:

docker compose up -d
docker compose ps
docker compose logs -f app

Notice that the app port is bound to 127.0.0.1, so it is only reachable from the server itself. The database has no published port at all; the app reaches it over Compose's internal network.

Step 5: Add a reverse proxy with HTTPS

A reverse proxy receives public traffic on ports 80 and 443, handles TLS certificates and forwards requests to your containers. Popular options include Caddy (automatic HTTPS with very simple configuration), Nginx with Certbot, and Traefik (configuration via container labels).

A minimal Caddyfile:

app.example.com {
    reverse_proxy 127.0.0.1:8080
}

Point your domain's A record to the server first. Our guide to DNS records explains how.

Docker and the firewall

This catches many people out. Docker writes its own iptables rules, and a port published as "8080:8080" is reachable from the internet even if UFW blocks 8080. To stay safe:

  • Bind published ports to localhost (127.0.0.1:8080:8080) unless they must be public.
  • Only publish ports 80 and 443 for the reverse proxy.
  • Never publish database ports publicly.
  • Verify with an external port scan of your own server.

Data, volumes and backups

Containers are disposable; data is not. Store anything important in named volumes or bind mounts, and include them in your backups. For databases, run a dump command inside the container rather than copying volume files while the database runs:

docker compose exec db pg_dump -U app app | gzip > /backup/app-$(date +%F).sql.gz

See our VPS backup strategy for off-site copies and restore testing.

Updating containers

  1. Pin image versions in Compose (for example postgres:16 or app:1.4.2), not latest, so updates are deliberate.
  2. Read the release notes, especially for databases.
  3. Back up, change the tag, then run docker compose pull && docker compose up -d.
  4. Check logs. If something breaks, revert the tag and recreate.

Security essentials

  • Use official or well-maintained images from trusted publishers.
  • Keep the host OS and Docker Engine updated.
  • Run containers as non-root users where images support it.
  • Do not mount the Docker socket into containers unless you understand the risk; it grants control of the host.
  • Set log rotation to prevent logs filling the disk. Add to /etc/docker/daemon.json: {"log-driver":"json-file","log-opts":{"max-size":"10m","max-file":"3"}}.

Monitoring resource use

Run docker stats to see live CPU and memory use per container. Set memory limits for services that might grow unexpectedly, so one container cannot starve the others. If you regularly use more than about 70% of your RAM, it is time to resize the VPS.

Common beginner mistakes

  • Using latest tags everywhere: an automatic pull can bring a major version change that breaks your app or database.
  • Storing data inside the container: anything not in a volume disappears when the container is recreated.
  • Publishing every port: exposes admin interfaces and databases to the internet.
  • Ignoring disk usage: old images, stopped containers and build cache pile up. Run docker system df to check and prune carefully.
  • Putting secrets directly in Compose files that end up in a public Git repository. Use an .env file or a secrets mechanism instead.

Docker or a traditional setup?

Docker is not required for every project. A single WordPress site on a control panel, or an app that the distribution packages well, can be simpler to run directly on the host. Docker shines when you run several services side by side, need consistent environments between development and production, or want to move between servers easily. Many teams use both: traditional packages for the base system, containers for applications.

What to run next

Popular self-hosted services that run well in Docker include analytics tools, uptime monitors, Git hosting, password managers, wikis and automation platforms. Start with one, learn the pattern of Compose, reverse proxy and backups, then add more.

Ready to start? Every RexaHost Linux VPS runs on KVM with NVMe storage, a dedicated IPv4 and IPv6, and full root access, in ten Standard locations.

Frequently asked questions

Can I run Docker on any VPS?

You need a VPS with full virtualisation such as KVM, which gives you your own kernel. All RexaHost VPS plans run on KVM.

How much RAM do I need for Docker?

Docker itself uses little memory. Size for your containers: 2 GB handles a few light services, 4 GB suits a typical web app with a database, and larger stacks need 8 GB or more.

Does Docker bypass my firewall?

Published container ports can bypass UFW rules because Docker manages iptables directly. Bind ports to 127.0.0.1 and expose only your reverse proxy.

Where should I store container data?

In named volumes or bind mounts on the host, so data survives container updates. Include these in your backups.

Should I use Docker Compose?

Yes for most single-server deployments. Compose files describe your whole stack in one place and make updates and rebuilds repeatable.

#docker#docker compose#vps#containers#reverse proxy#self-hosting

Plans in this article

Servers mentioned here

VPS Basic

Standard
$2.79 /mo
$5.38Save 48% billed monthly
  • 1 vCPU
  • 2 GB RAM
  • 60 GB NVMe
  • 3 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6
Most popular

VPS Pro

Standard
$4.69 /mo
$10.42Save 55% billed monthly
  • 2 vCPU
  • 4 GB RAM
  • 120 GB NVMe
  • 5 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6

VPS Business

Standard
$8.39 /mo
$19.06Save 56% billed monthly
  • 4 vCPU
  • 8 GB RAM
  • 240 GB NVMe
  • 7 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6

Keep reading

Related articles

Live Chat · offline