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?
4 Answers
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.
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.
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.
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.

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