What’s a good way to schedule PostgreSQL backups with Docker?

November 8, 2026 4 answers
Asked by pocket_solder

I want to run regular backups of a PostgreSQL database in Docker. Should the schedule live inside the database container, or is there a better way to trigger it?

Answers

m5!Trestling

I’d keep scheduling separate from the database container. A small scheduler container can run a command such as pg_dump against the database over the Docker network, then write the dump to a mounted backup directory. That keeps the database container focused on PostgreSQL and makes the backup schedule and logs easier to manage.

Use a cron-capable tool designed for containers, and make sure the backup destination is persistent or remote. Test restoring a dump too, since a file existing is not proof that it can be recovered.

Reply to this answer
OllieBee

You can also schedule the job from the host. The host’s cron can launch a short-lived PostgreSQL client container, connect it to the database’s Docker network, and mount the backup destination. That avoids adding a long-running scheduler process to either the database container or the client container.

Pass credentials securely rather than embedding a password directly in the command, and check that failed dumps produce a visible error and a nonzero exit status.

Reply to this answer
A9~Firmware

There are scheduler containers that can run commands on a timetable, including tools such as Ofelia or Deck Chores. They can be convenient if you already manage your services through container configuration. The key detail is that the scheduled task should perform a database-aware dump, not just copy the live data volume.

Reply to this answer
f9~Register

For backups, I’d distinguish a PostgreSQL dump from a volume snapshot. Copying the database’s storage volume while PostgreSQL is running may not give you a reliable, consistent backup. Run pg_dump for a logical backup, store the result somewhere durable, and periodically verify that you can restore it.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions