Abdulkader Safi

Deploying a Rust web app to a VPS with one docker compose command

Private CRM installs and updates with docker compose up -d --build: PostgreSQL, the app, a queue worker and a scheduler, behind Caddy, shipped over rsync.

1 min read

Share
Docker compose diagram with database, app, worker and scheduler containers behind a Caddy reverse proxy

The whole install for Private CRM is one command, and the update is the same command:

docker compose up -d --build

That starts four containers, migrates the database, and creates the admin account on first run. This post covers how the compose file is laid out, what happens on boot, and how code gets to the server.

One image, four containers

The compose file defines the app once as a YAML anchor and starts it three ways, plus PostgreSQL:

x-app: &app
    build: .
    restart: unless-stopped
    env_file: .env
    environment:
        DB_CONNECTION: postgres
    volumes:
        - storage:/app/storage

services:
    db:
        image: postgres:17-alpine
        healthcheck:
            test: ['CMD-SHELL', 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}']
    app:
        <<: *app
        command: serve
        depends_on:
            db:
                condition: service_healthy
    worker:
        <<: *app
        command: worker
        depends_on:
            app:
                condition: service_healthy
    scheduler:
        <<: *app
        command: scheduler
        depends_on:
            app:
                condition: service_healthy

(Trimmed. The real file also has ports and the app's health check on /up.)

The worker runs queued jobs like CSV imports (part 7). The scheduler runs task reminders every minute and the nightly quiet-deal and overdue-invoice checks (part 9). Both wait for the app to be healthy, which means migrations have already run when they start.

Locally I run SQLite. Here it's PostgreSQL, and the test suite passes on both (part 2 has the one bug that difference caused).

What happens on boot

On every start the app:

  • runs any new migrations
  • creates the admin from ADMIN_EMAIL and ADMIN_PASSWORD if no admin exists yet, and never adds demo data
  • makes an APP_KEY on first start and keeps it in the storage volume

That last one removes a step people get wrong. You leave APP_KEY empty in .env, and the key survives rebuilds because it lives in a volume, not in the image.

Data lives in two volumes, pgdata for the database and storage for uploads and the key, so --build never touches it. The guide ends with one warning: docker compose down -v deletes both.

Building Rust on a small VPS

The first build compiles the Rust server and takes 5 to 15 minutes on a small VPS. Later builds reuse the cache and take seconds to a few minutes. The server needs at least 2 GB of RAM, or swap, or the compiler gets killed halfway. If image size bothers you, I covered that in my guide to reducing Docker image size.

Getting code there with rsync

No registry, no CI. An npm script sends the working copy to the server:

npm run rsync:prod

It runs rsync -azP --delete and excludes .git, .env, storage, target, node_modules, build output, tests, the local SQLite database and logs. The useful detail: --delete never removes a file that matches an exclude, so the server's own .env is safe even though the local one isn't sent.

An update is then one line:

npm run rsync:prod && ssh myserver 'cd /var/www/crm && docker compose up -d --build'

My rsync guide covers the flags.

A domain with Caddy

The app binds to 127.0.0.1 on a port of your choice, so the only way in is through the proxy. Caddy needs two lines:

crm.example.com {
    reverse_proxy 127.0.0.1:8010
}

Caddy fetches the certificate. Two settings on the app side make it work:

  • APP_URL must match the address in the browser. The app only answers requests for that host.
  • TRUSTED_PROXIES set to the Docker network range (172.16.0.0/12) tells the app to believe Caddy when it says the visitor used https.

Https isn't optional here. Browsers only allow push notifications on https or localhost, so push starts working once the certificate is in place. If reverse proxies are new to you, start with self-hosting with a reverse proxy.

Push keys, once

VAPID keys come from the same image:

docker compose run --rm --no-deps app push:keys

Make them once and keep them. New keys cut off every device that already turned notifications on.

Backups and migrations that rewrite data

The guide has two backup commands: a pg_dump piped through gzip for the database, and a tar of the storage volume for uploads and the key. Copy both off the server.

Migrations run on start, which is convenient right up until one rewrites data. The pull request for the agents' feature requests (part 6) included migration 032, which maps old free-text deal sources to a fixed list. Its deploy note said to take a backup first. Every later pull request ends with a "Deploying" section saying which migrations run and what they change.

Two copies on one server

A second folder with a different COMPOSE_PROJECT_NAME, APP_PORT and APP_URL gets its own database and volumes. Handy for a staging copy next to production.

What to take from this

Run your worker and scheduler as separate containers from the same image, gate them on the app's health check, and keep the app key and uploads in a volume. Then make the update command identical to the install command, so there's only one thing to remember. Before trusting it with real data, run through a self-hosted security checklist.

The last part covers the gap checklist and the code review that found leaks no test had caught.

Last updated 4 Dec 2026 · filed under Rust, docker, crm, hosting

Every entry on this project

12 build notes, in order

Including the ones where nothing worked. You are on part 11.

Read the series →

FAQ

Frequently asked questions

How do you run a queue worker and scheduler with Docker Compose?

Build one image and start it three ways. Private CRM's compose file defines the app once as a YAML anchor, then runs it as serve, worker and scheduler services. The worker and scheduler wait for the app's health check to pass, so migrations have run before they start.

How much RAM does building a Rust app in Docker need?

Private CRM's deploy guide asks for at least 2 GB of RAM or swap, or the compiler may be killed during the build. The first build on a small VPS takes 5 to 15 minutes. Later builds reuse the cache and take a few seconds to a few minutes.

Why does my app behind Caddy think requests are http?

The proxy talks to the app over plain http and says the visitor used https in a forwarded header. The app has to trust the proxy to believe it. Private CRM reads a TRUSTED_PROXIES setting, set to the Docker network range, so it builds https links behind Caddy.

Does rsync --delete remove my server's .env file?

Not if .env is excluded. rsync --delete never removes files that match an exclude pattern, so Private CRM's rsync script excludes .env, storage, the local database, target, node_modules and build output, and the server's own .env stays put.

Written by

Abdulkader Safi

Software Engineer

Lead engineer at DSRPT, from Lebanon and based in Kuwait. I write about the tools and bugs from real client work, with the numbers I measured.

About me → GitHub LinkedIn

Need this kind of work done on your project?

Start a project →

Keep reading

More from Private CRM: an AI CRM where Claude does the data entry and you make the calls

All 12 entries →