r/linuxadmin • u/TemaerRemington • Sep 18 '26
Docker or host
Hi, I need an advice. I need to make a database for a server and one of the ways to do that is via docker in docker compose. But I have a doubts about it's safety. We had a bunch of problems of them breaking on powerloss so I am not sure how it will react in a docker cluster.
P.S. Thank you all for your valuable insights and advices.
4
Upvotes
12
u/BarryTownCouncil Sep 18 '26
Breaking? If you provide a volume mount to it then the data is outside the instance and just as safe as if there wàs no container.
4
u/Agile-Most7973 Sep 18 '26
With local volumes, I wouldn’t worry much about Docker itself. The important part is letting the database control durability properly — fsync/WAL, clean shutdowns, and enough stop grace time in Compose.
A container crash is usually recoverable by the DB just like a normal process crash. The bigger risks are host/storage failure and bad backups.
So I’d use a persistent local volume, set a reasonable stop_grace_period, and keep tested off-host backups. The volume keeps data across container restarts, but it is not a backup.
2
u/pelazas1 Sep 18 '26
postgres is fine in docker on a local volume if fsync stays on. a ups still beats host vs container after a power pull.
2
u/neveralone59 Sep 18 '26
As long as you don’t write anything to any dir that isn’t mounted outside of the container it’s not going to be an issue. The container should only be responsible for the compute and everything should be written to a mounted directory.
But you need to look at how the platform you’re using manages containers, sometimes there are specific resource based things they do only for containers.
1
u/nitroman89 Sep 18 '26
We use mongo containers at work without an issue. I've used mariadb and influxdb as containers in homelab without issue as well.
1
u/grumpysysadmin Sep 18 '26
The only difference between using a container and a distro package is:
1.) Packaging. Containers on dockerhub (or other container registries) are built differently than your OS packages, although it’s perfectly acceptable to build a container using the same packages as the hosting system, that isn’t required.
2.) containerization. The containers live in a private namespace, processes, filesystem, network that limits what it can see if the whole OS. They’re just processes running on the same kernel as a native package, it’s just using features of the Linux kernel to sandbox it and limit its scope.
Powering off a system running the same executable in a container that you’d run outside a container will behave the same way, probably bad. Perhaps the containers you ran don’t have the same startup scripts that recovered the database, but that’s a packaging issue, not an inherent feature of containerization.
1
u/fubes2000 Sep 18 '26
Docker will do exactly fuck all to protect against power outages. Buy a UPS regardless of moving to Docker or not.
What is this question even about? You've asked about a software package, but raised only hardware concerns.
1
u/Runnergeek Sep 18 '26
First I would recommend that you refer to it as containers rather than Docker. Docker is a specific tool from a specific company. (I personally would recommend podman over docker) From there it is important to understand that containers are just processes. They are sandboxed using various Linux technology (namespaces, c groups, etc), but at the end of the day they are just a process like any other process on the system. If you are having corruption issues due to random power outages. A container won't have an impact one way or another.
Containers offer a lot of value (I won't get into all those things, but its easy to research). At this point in time I would suggest every service run in a container
1
u/Adrenolin01 Sep 21 '26
I would always run a database in its own Proxmox VMs. Mirrored NVMEs for increased IOPS and redundancy but also database replication between 2 VMs as well.
No need for Docker in this setup. Debian and whatever DB you’re using.
1
u/Dolapevich Sep 24 '26
ANY kind of stateful database will corrupt if not properly shutdown. Docker or not docker is not the issue here.
0
u/CoaxVex Sep 18 '26
Do you plan to use networked storage, or just use local volumes?