Docker deployment with Compose: DIY VPS vs fixed-cost managed

By Mark Hayes
Docker deployment with Compose: DIY VPS vs fixed-cost managed

Your app runs perfectly with docker compose up on your laptop. The obvious next step is to rent a VPS, copy the compose file over, and run the same command in production. Plenty of successful products started exactly that way, and for some of them it is still the right call.

It is also the setup behind a lot of 2 AM outages. The compose file that works locally is missing half of what production needs, and the half it is missing is the part nobody sees until it breaks.

This guide does two things. First, it shows what a production-grade Docker deployment with Compose actually looks like on a single VPS, with health checks, TLS, log rotation, and off-site backups. Second, it lays out everything that setup still leaves you to own, and compares it with deploying the same containers to a managed platform at a fixed monthly cost. You can pick either path with clear eyes.

The local compose file is not a production compose file

A typical development docker-compose.yml looks like this:

services:
  app:
    build: .
    ports: ["3000:3000"]
    environment:
      DATABASE_URL: postgres://postgres:postgres@db:5432/app
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: postgres

Deployed as-is, this has at least six production problems:

  1. No TLS. The app is served over plain HTTP on port 3000.
  2. No restart policy. If the process crashes or the server reboots, it stays down.
  3. No persistent volume for Postgres. Recreate the container and the data is gone.
  4. No health checks. The app can start before the database is ready and crash-loop.
  5. Unbounded logs. Docker's default json-file driver keeps logs until the disk is full.
  6. No backups. One bad migration or disk failure and there is nothing to restore.

A production Docker deployment on a single VPS

Here is a compose file that fixes all six. It uses Caddy as the reverse proxy because it obtains and renews TLS certificates automatically, which removes a whole class of Certbot and nginx configuration work.

# docker-compose.prod.yml
x-logging: &default-logging
  driver: json-file
  options:
    max-size: "10m"
    max-file: "3"

services:
  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      app:
        condition: service_healthy
    logging: *default-logging

  app:
    image: ghcr.io/your-org/your-app:${APP_VERSION:-latest}
    restart: unless-stopped
    env_file: .env.production
    environment:
      DATABASE_URL: postgres://app:${POSTGRES_PASSWORD}@db:5432/app
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:3000/healthz"]
      interval: 10s
      timeout: 3s
      retries: 5
      start_period: 20s
    logging: *default-logging

  db:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: app
      POSTGRES_DB: app
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d app"]
      interval: 5s
      timeout: 3s
      retries: 10
    logging: *default-logging

volumes:
  pgdata:
  caddy_data:
  caddy_config:

A few notes on the choices:

  • No version: key. It is obsolete in Compose v2 and only produces a warning.
  • ${POSTGRES_PASSWORD} is interpolated by Compose from your shell or a .env file next to the compose file, not from env_file. Keep that .env out of Git and readable only by the deploy user.
  • The database has no ports: entry, so it is reachable only from other containers on the compose network, not from the internet.
  • The app image comes from a registry with a pinned version tag instead of being built on the server. Building on a small production VPS competes with live traffic for CPU and memory, and it is a common cause of out-of-memory kills during deploys.
  • The health check uses wget because it ships with Alpine-based images. If your image does not include wget or curl, add one or write the check in your app's runtime.

The Caddyfile is three lines:

app.example.com {
	reverse_proxy app:3000
}

Point your domain's DNS at the server, and Caddy handles certificates on first request.

Deploying a new version

With images built in CI and pushed to a registry, a deploy is a pull and a recreate:

#!/bin/sh
# deploy.sh, run on the server
set -e
export APP_VERSION="$1"
docker compose -f docker-compose.prod.yml pull app
docker compose -f docker-compose.prod.yml up -d --wait app
docker image prune -f

--wait blocks until the new container reports healthy, so the script fails loudly if the release is broken. Note that this still recreates the app container in place, which means a few seconds of errors during each deploy. True zero-downtime releases on a single host need either a second app container behind the proxy with a blue-green switch, or a tool built for it.

Off-site backups

A backup on the same disk as the database is not a backup. Stream a dump to S3-compatible storage from a cron job on the host:

#!/bin/sh
# /usr/local/bin/pg-backup.sh
set -e
STAMP=$(date +%Y%m%d-%H%M)
docker compose -f /srv/app/docker-compose.prod.yml exec -T db \
  pg_dump -U app -d app --format=custom \
  | aws s3 cp - "s3://your-backup-bucket/pg/app-$STAMP.dump" \
      --endpoint-url "$S3_ENDPOINT"
15 3 * * * /usr/local/bin/pg-backup.sh >> /var/log/pg-backup.log 2>&1

Add a lifecycle rule on the bucket to expire old dumps, and, crucially, restore one into a scratch database every month to prove it works.

What the DIY setup still leaves you to run

The compose file above is solid. It is also only the beginning of the job. Here is what you still own on a self-managed VPS:

ResponsibilityWhat it involves
OS security updatesunattended-upgrades, kernel reboots, SSH hardening, firewall rules
Disk spaceMonitoring volume growth, pruning images, Postgres WAL and bloat
Monitoring and alertingAn external uptime check, disk and memory alerts that actually wake you
Backup verificationMonthly test restores, checking the cron job still runs
Postgres upgradesMajor versions need pg_dump and restore or pg_upgrade; the data directory is not forward-compatible
ScalingResizing the VPS means downtime; horizontal scaling means a load balancer and moving Postgres off the box
Zero-downtime deploysBlue-green container switching, or accepting brief errors per deploy
Incident responseYou, at whatever hour the disk fills

None of this is hard in isolation. Together, it is a part-time job, and for a solo founder it competes directly with shipping the product.

DIY vs managed: the real cost comparison

The VPS itself is cheap. Mainstream providers sell a 2 to 4 GB instance for somewhere in the range of $10 to $25 per month at the time of writing (check current pricing, since it changes). Add a small amount for off-site backup storage and an uptime monitor.

The number that matters is the one that does not show up on an invoice:

  • Setup: a careful first production setup like the one above takes most founders one to two days, including DNS, TLS, backups, and hardening.
  • Maintenance: a few hours a month for updates, pruning, checking backups, and reviewing alerts.
  • Incidents: the six-hour Postgres-out-of-disk outage is common enough to plan for.
DIY Compose on a VPSManaged platform
Monthly invoiceLow and fixedFixed plan with included usage
Your time per monthHours, plus incidentsClose to zero for infrastructure
TLS, routingCaddy, your configIncluded
Database backupsYour script, your bucket, your restore testsManaged
ScalingResize or re-architectAutomatic
ControlFull root accessPlatform-defined limits
Best forSteady workloads, ops-comfortable teamsSolo founders shipping an MVP
The DIY path is fixed-cost in dollars and variable-cost in hours. The managed path is fixed-cost in both.

If you enjoy operations, have time, or need full control of the host, the DIY route is a legitimate choice, and the compose file above is a good foundation. If your binding constraint is time before a launch, the calculation usually goes the other way.

The same stack on Granite.so

The managed version keeps your Docker image and throws away the glue. Nothing about your application changes; you are only changing where each compose service lives.

Map each service in your compose file:

  • app becomes a Granite.so service. Deploy it from your Docker image in a registry, or connect the Git repository so every push to main rebuilds and redeploys automatically. Environment variables from .env.production go into the service settings.
  • db becomes a managed database. The connection string is injected into the app as an environment variable, and backups are handled by the platform. The pgdata volume, the backup cron job, and the monthly "is the cron still running?" check all go away.
  • caddy disappears. TLS certificates, custom domains, and routing are part of the platform.
  • Uploads that were on a local volume move to S3-compatible storage with a CDN, which your app accesses with the standard S3 SDK and a different endpoint.
  • Scaling is automatic, so there is no load balancer to add when traffic grows.

You do not upload the compose file itself. You recreate each piece in the dashboard, which takes minutes because there are only one or two pieces left.

Migrating the data is a single dump and restore from your VPS:

docker compose -f docker-compose.prod.yml exec -T db \
  pg_dump -U app -d app --format=custom --no-owner > app.dump

pg_restore --dbname="$GRANITE_DATABASE_URL" --no-owner --no-privileges app.dump

Stop writes on the old server before the final dump, verify the data on the new database, then switch DNS.

On cost, the Hobby plan is $9 per month and includes $15 of monthly usage credits, which fits a typical MVP with an app, a database, and a storage bucket. The Advanced plan at $39 per month gives more headroom for your first paying users. Check the pricing page for what each plan includes today. Either way, you know the number before you deploy.

Honest limits of the managed route

  • You give up root. Custom kernel settings, unusual Postgres extensions, or sidecar processes may not be possible. Check what your app depends on first.
  • Platform limits apply. Resource ceilings, build timeouts, and supported regions are set by the provider.
  • It does not fix application bugs. A managed platform prevents infrastructure outages like a full disk, but a bad migration or a memory leak in your code still needs your attention.

The good news is that nothing here locks you in. Your Dockerfile, a standard Postgres dump, and S3-compatible storage all move to a VPS or another provider if you ever need to.

Choose the path that matches your constraint

A production Docker deployment on a VPS is a real option, and if you take it, use the compose file above: health checks, restart policies, log rotation, a TLS-terminating proxy, and off-site backups you actually test. Just budget the hours honestly.

If you would rather spend those hours on the product, Granite.so runs the same Docker image with a managed database and CDN-backed storage on a fixed plan starting at $9 per month. Keep your containers, lose the server.

Keep reading

More posts tagged “Tutorials”.
Be first in line for updates
and special pricing
Get early access to new features and exclusive discounts delivered straight to your inbox