
Docker + Postgres on a single box: the small-team setup that actually holds up
Docker and Postgres on one box, done right: the real setup, what it handles, where it breaks, and the one thing to fix before trusting it with real data.
Docker Postgres on a single box is a legitimate production setup for a small team, not a local-dev shortcut that happens to also run in production. Get three things right and it holds up: the data volume actually persists across a restart, backups exist before you need them, and someone specific knows what breaks first as load grows. Get any of those wrong and it's indistinguishable from not having a database strategy at all.
The actual setup
A minimal, real docker-compose.yml for this:
yaml
services:
postgres:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
volumes:
pgdata:Two details here are where people get burned. First, pin a real version tag (postgres:16, not postgres:latest), so an unrelated docker compose pull doesn't silently jump you to a new major version. Second, the volume mount path depends on which Postgres version you're running: /var/lib/postgresql/data for Postgres 17 and earlier, /var/lib/postgresql for Postgres 18 and later, which moved to a version-specific internal layout. Mount at the wrong path for your version and the container starts fine, looks fine, and quietly doesn't persist anything across a restart.
Third, bind the published port to localhost (127.0.0.1:5432:5432), or remove the ports section entirely if only other containers in the same Compose project need the database; they can reach it at postgres:5432 on the Compose network. A bare "5432:5432" publishes Postgres on every network interface, and Docker's own firewall rules bypass ufw, so a firewall you think is protecting it may not be. Exposed Postgres instances are routinely found and brute-forced.
POSTGRES_PASSWORD is the only required environment variable. Never set POSTGRES_HOST_AUTH_METHOD=trust outside a throwaway local container, it allows passwordless access even when a password is configured, which defeats the point of setting one.
Backups, and proving they work
A backup you haven't restored isn't a backup yet. The minimum for this setup:
Dump on a schedule. A nightly cron job on the host:
bashdocker compose exec -T postgres pg_dump -U postgres -Fc mydb > /backups/mydb-$(date +%F).dumpCopy it off the box. A dump on the same disk dies with the disk. Sync
/backupsto object storage or another machine, and delete old dumps on a schedule.Test a restore. Restore a recent dump into a scratch container and check that the tables and row counts look right:
bashdocker run -d --name pg-restore-test -e POSTGRES_PASSWORD=test postgres:16 docker exec -i pg-restore-test createdb -U postgres mydb docker exec -i pg-restore-test pg_restore -U postgres -d mydb < /backups/mydb-latest.dump
Also check persistence once: restart the container (docker compose restart postgres) and confirm your data is still there before you rely on it. What GitLab's Postgres incident teaches about backups shows why the restore test matters most.
Dumps give you a nightly restore point, not point-in-time recovery. If losing a day of writes is unacceptable, you need WAL archiving or a managed service.
What this handles vs. where it breaks
| Situation | Verdict |
|---|---|
| A small team's real production traffic, one app, standard read/write load | Handles this comfortably |
| Nightly backups, manual failover if the box goes down | Fine, as long as someone actually owns doing it |
| Automatic failover, point-in-time recovery without building it yourself | This setup doesn't give you that. A managed service does |
| A second person genuinely on call for the database, not just you | Also not this setup, that's an ops-team problem, not a Docker problem |
The real dividing line is ownership, not scale. Managed Postgres options exist for a reason: self-hosting on a single box is where databases quietly get lost the moment "someone owns backups and monitoring" stops being a specific person with that written down. Nobody watching causes that, not Docker being unreliable.
What it actually costs
A single box running both the application and Postgres is priced like any other small VPS or droplet. For how the egress line item specifically adds up once real traffic is moving data off that box, see our per-provider pricing breakdown. The Postgres side itself adds close to nothing beyond the box you're already paying for, that's the actual appeal of this setup. What it doesn't include is the cost of someone's time when a 3am disk-full alert has no one assigned to answer it.
The verdict: this setup is right for a small team that can name the specific person responsible for backups and would notice if a restore never got tested. It's the wrong call the moment that person is "whoever's around," not because Docker and Postgres can't handle real production traffic on one box, they can, but because the thing that actually fails here is ownership, not the technology.
Update, October 23, 2026: we've bound the published port to localhost (the earlier example exposed Postgres on every interface), added backup, restore and persistence checks, and labeled the I/O point as our judgment.
Self-host if the team is small, the budget is tight, and someone is willing to own backups and monitoring. Use a managed service once that owner isn't a specific person with the responsibility written down; that gap is where self-hosted databases get lost, not Docker itself.
Yes, for a single-box setup. Compose declares the container, volume and network; it doesn't make Postgres less production-grade. What matters is the same as any Postgres install: persistent volumes, tested backups, a real password, and not exposing the port publicly.
In our judgment, often disk I/O, because the application and database share the same disk and compete for it as tables and traffic grow. Check your own metrics: if disk wait or I/O utilization climbs while CPU and memory have headroom, that's the point to move Postgres to its own box or a managed instance.
- Docker Hub, official postgres image: Environment variables, volume mount path by Postgres version, and current recommended tags, verified 2026-08-09.