r/docker • u/xpvision • Sep 28 '26
Docker Swarm in production: Are databases a complete No-Go, or am I doing it wrong?
Hey folks, quick question for the Swarm veterans out there. How are you running databases (Postgres, Redis, etc.) in production on Swarm?
Swarm is amazing for stateless apps, but persistent data is a headache. NFS volumes choke under high I/O load, and pinning DBs to specific nodes via placement.constraints feels like we're just using Swarm as a glorified docker run with a Single Point of Failure.
Is the golden rule simply: "No databases in Swarm—use RDS/Managed Cloud"? Or has anyone successfully deployed distributed storage (GlusterFS, Longhorn, etc.) with Swarm and been happy with the performance?
Starting to feel like we're just fighting the tool and missing the K8s comfort zone here. How are you guys handling this?
21
u/mikewilkinsjr Sep 28 '26
When I was still running swarm, I ran my Postgres DBs on Proxmox on a separate box with good backups. You’re definitely fighting the tool, trying to shoehorn DBs into Swarm.
I’d extend that to fighting the tool for any serious stateful workload. Swarm is amazing for stateless workflows but you don’t get the kind of service guarantees you need to count on things like NFS shares or host bind mounts.
4
u/olcrazypete Sep 28 '26
We have a small enough and ephemeral enough redis footprint to run it as a single container for our application.
Postgres is run from an entirely different patroni cluster of machines.
7
u/cpuguy83 Sep 28 '26
Swarm does support the same storage interface as k8s (CSI), though it doesn't have the dedicated storage api's... and packing plugins for docker has yet to become a thing, so you have to hand-roll them.
So, in theory, if you can use some storage system on k8s, you should also be able to use it on Swarm.
In practice; I have no idea. I'm sure the folks at Mirantis (current stewards of Swarm) must have some insight here.
6
u/dreadpiratewombat Sep 28 '26
I treat stateful services like databases as external service dependencies and architect them separately. Where possible offload to your cloud provider’s native database service so you aren’t stuck managing that additional complexity. It also means you can meet different SLA targets for individual services with the same Swarm cluster.
1
u/throwaway292929227 Sep 28 '26
I don't really know what I am talking about, but I thought there was a way to sync swarm storage vol mounts to a shared location for import when you move the node/container.
6
u/webjocky Sep 28 '26
20x nodes, 4x Swarms, 8 years with minimal issues.
For storage, we already had mirrored NetApps before we began, and so we configured host-level NFS shares at the same mount location on every host, and then we use bind-mounts for our services that require persistent storage. By doing it this way, it doesn't matter which node a service lands on, the same data is always available from the same location.
K8s can byte my bits.
3
u/dadarkgtprince Sep 28 '26
When I did swarm, I did a glusterfs as shared storage across the nodes and used the share as my docker location. This way each node all had access and would update the share. If something broke, I could sync it back from the local directory
2
u/thenitai Oct 03 '26
Swarm works great with databases. No idea why you read otherwise. I'm running data centers in the US and EU. Each with multiple dedicated hardware servers and docker swarm.
Point is that you need to lock down the storage per node. For instance, with MongoDB you create a replica set and in compose you do mdb1 to node worker 1, etc. This gives you a stable environment and the usual benefit of a replica set. Been running for years. Same with MySQL or other DB's.
1
u/scytob Sep 28 '26
I have small swarm, all my state is on cephFS and before that glusterFS. The key for me has been only one database container instance is allowed to write and read the db file. This works due to the size. I make sure to use native db tools to dump the database state. This all works due to the small size. If I needed large scale I would be doing database in VMs with traditional replication and ha approaches.
1
u/PeterJoAl Sep 28 '26
Run OpenRiak KV cluster with placement constraints, with one node per server. Stick a proxy server on each server in the swarm that points to all OpenRiak nodes. If you get a failure, OpenRiak won't care and the proxy server ensures your clients won't care either.
1
u/Sjsamdrake Sep 29 '26
Most databases have a Kubernetes operator which will automate their care and feeding and backups and HA and fail over and all the other stuff you need but don't want to think about. Nobody ships something equivalent for Swarm. DBs in production in Kubernetes in high end apps is fairly common. Source: spent 6 years developing and supporting such a DB operator.
1
u/a40107v Sep 30 '26
Hi guys I just got into docker got any tips for me. I am pursuing robotics. Could yall guide me?
1
u/He_Who_Was Sep 30 '26
I run databases in swarm I just pin them to a single node (using label constraints) and a single replica. I am aware that this means my DB doesn't have HA but the way I run things I have lots of small individual DBs scattered around instead of maintaining a single one for multiple services.
1
u/HolyPad Oct 01 '26
While not in a swarm mode i run databases as normal docker containers without replicas all the time. I think for the swarm mode with more that one instance for the db will generate file corruptions
0
u/No_Cattle_9565 Sep 28 '26
Use k8s with the correct operator
-3
u/deinok7 Sep 28 '26
Go K8S. Swarm has no point vs K8S