Is running a production database in Docker safe after power loss?

September 17, 2026 4 answers
Asked by VelvetCedar42
I need to run a database for a server and am considering using Docker Compose. I'm concerned about reliability and data corruption after unexpected power outages, especially because we've had MongoDB corruption and severe MariaDB/MySQL failures in the past. The database would use a local persistent volume rather than network storage. How well do databases such as PostgreSQL handle power loss in containers, and are there any Docker or Compose settings I should use to reduce the risk?

Answers

NorthstarPanda6
The biggest risks are the host disk, filesystem, and lack of tested backupsโ€”not the container boundary. Use a local persistent volume, configure a reasonable Compose stop grace period, watch disk capacity, and keep backups on separate storage. Make sure youโ€™ve actually tested restoring those backups, because a volume alone wonโ€™t help if the host or drive fails.
Reply to this answer
MiraHollow7
Docker itself usually isnโ€™t the main concern. With a properly configured persistent volume, the database files remain on the host and a container restart is similar to restarting the database process directly. Keep durability features such as PostgreSQLโ€™s fsync and WAL enabled, give the container enough time to shut down cleanly, and monitor available disk space. A persistent volume protects data across container recreation, but it is not a backup.

QuietOrbit18: In practice, running out of disk space has caused us more trouble than Docker or power loss. Monitoring disk usage is definitely important.

Reply to this answer
AmberLynx31
PostgreSQL generally works well in Docker with a local volume as long as fsync remains enabled and the underlying storage is reliable. An unexpected shutdown can still require crash recovery, but that is normal database behavior and is usually handled automatically. A UPS is more valuable than choosing between a container and a host installation, since it reduces the chance of an abrupt power cut in the first place.
Reply to this answer
CopperMeadow24
Containers are commonly used for MongoDB, MariaDB, InfluxDB, and PostgreSQL without inherent reliability problems. The important details are correct database settings, durable storage, sufficient free space, and orderly shutdowns. If you have already seen repeated corruption, investigate the power, disks, filesystem, and backup process rather than assuming Docker is the cause.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions