Docker on a VPS: When It Helps and When It Gets in the Way

What Docker gives you on a single server, the workloads it suits and the ones it complicates, the firewall and networking gotchas, and a sane compose setup.

Published
Reading time
4 min

Docker packages an application with everything it needs to run, so it behaves the same on a laptop and on a server. On a fleet of machines managed by a platform team, that is transformative. On one VPS running one website, it is often an extra layer between you and your problem. Here is an honest account of where it helps, where it does not, and how to use it well when it does.

What Docker gives you

  • Reproducibility. The app, its runtime and its dependencies are one image. "Works on my machine" becomes "works everywhere the image runs".
  • Isolation. Two apps needing different PHP or Node versions coexist without conflict.
  • Easy trials. Running Redis, a mail catcher, or Postgres for a weekend is one line, and removing it leaves nothing behind.
  • Clean deploys. Build an image, start the new container, stop the old one. Rollback is starting the previous image.

What it costs on a VPS

  • Another layer to debug. A 502 might be Nginx, or the container's network, or the process inside, or a volume permission. Each adds a place to look.
  • Memory. Each container runs its own copy of libraries; five containers of PHP apps use more RAM than five PHP-FPM pools on one host.
  • Firewall bypass. Docker writes its own iptables rules. A container started with -p 3306:3306 is reachable from the internet even if ufw denies port 3306. This surprises everyone once.
  • Updates. The host's apt upgrade does not patch the OpenSSL inside your containers. Images must be rebuilt or re-pulled — a process most single-server setups never automate.
  • Logs, backups and monitoring all need container-aware versions of what you already had.

When it helps

  • The app is distributed as a container (Gitea, Mattermost, n8n, Uptime Kuma, many self-hosted tools) and the vendor's compose file is the supported install.
  • You run several apps with conflicting runtimes on one server.
  • You want identical staging and production and deploy from CI.
  • The stack has many moving parts (app, worker, Redis, Postgres, Meilisearch) that compose describes better than a page of install steps.

When it gets in the way

  • A WordPress or PHP site. PHP-FPM behind Nginx on the host is simpler, faster, uses less memory, and every guide on the internet assumes it. Plesk manages it. Containerising WordPress on a single VPS buys nothing except complexity.
  • A Laravel app on one server. Same. A systemd unit for the queue worker and PHP-FPM for the web is two files.
  • Anything where you will be the one debugging it at midnight and you are not fluent in Docker.

If you do use it: a sane setup

Install the official packages, not the distribution's older ones:

bash
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker deploy

Describe the stack in a docker-compose.yml, and bind published ports to localhost, with Nginx on the host as the reverse proxy:

yaml
services:
  app:
    image: ghcr.io/example/app:1.4.2       # pin a version, never :latest in production
    restart: unless-stopped
    ports:
      - "127.0.0.1:8080:8080"              # localhost only — the firewall stays in charge
    env_file: .env
    volumes:
      - ./data:/app/data
    depends_on: [db]
    logging:
      options: { max-size: "10m", max-file: "3" }
  db:
    image: postgres:16
    restart: unless-stopped
    volumes:
      - pgdata:/var/lib/postgresql/data
    env_file: .env
volumes:
  pgdata:
bash
docker compose up -d
docker compose logs -f app
docker compose pull && docker compose up -d     # update to new images

The points that matter: 127.0.0.1: on every published port; restart: unless-stopped so a reboot brings it back; pinned image tags; named volumes for data that must survive docker compose down; log rotation so a chatty container does not fill the disk.

Backups and disk

Data lives in volumes and bind mounts; back those up, plus the compose file and .env, and you can rebuild the whole stack anywhere. Database containers need a docker compose exec db pg_dump (or mysqldump) rather than copying the volume live.

Docker's images and build cache grow silently; docker system df shows how much, docker system prune reclaims it. This is a regular entry in finding what fills the disk.

Security notes

Do not run containers as root inside if the image supports a user (user: "1000:1000"). Do not mount the Docker socket into containers unless you understand that it is root on the host. Keep images updated: docker compose pull monthly at least, or use Watchtower for automatic updates on non-critical stacks. Scan with docker scout or Trivy if the images are yours.

What we do

On a VPSPioneer managed VPS, we will run a compose stack for an application that ships as one — set up as above, behind Nginx, with the volumes in the nightly backup — and we will suggest PHP-FPM on the host when the application is a PHP site, because that is what we would rather support at midnight too.

#docker#containers#vps#servers#devops

Keep reading

More from Servers

All guides

Servers

How to Set Up Nginx as a Reverse Proxy

Put Nginx in front of a Node, Python, Go or container app: proxy config, forwarding headers, WebSockets, HTTPS, caching, and several apps on one server.

3 min read →

Servers

Hetzner and DigitalOcean Alternatives for UK & EU Projects

A fair framework for choosing a Hetzner alternative or DigitalOcean alternative in the UK and EU: location, billing, support, backups and how to test.

8 min read →

Servers

How to Monitor a Server: Uptime, Resources and Alerts

The three layers of server monitoring — external uptime checks, resource metrics with alerts, log-based detection — free tools for each, and thresholds to set.

3 min read →