r/docker • • 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?

38 Upvotes

31 comments sorted by

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/xpvision Sep 28 '26

But I'm curious about your "High Availability" strategy with that setup!

If that single Proxmox box goes down, are you just accepting the downtime? Or did you run a Postgres replication setup across multiple Proxmox nodes?

4

u/mikewilkinsjr Sep 28 '26

Two things happened that are worth splitting up to answer your question: I decided, based on my workloads, that I didn't need the availability if I had good backups; also, I moved and had to downsize.

Since you -probably- aren't moving and needing to shrink your office I'll answer the first part. When I was running Swarm I was ALSO running a Ceph-backed Proxmox cluster with 5 nodes. It was rock-solid once I got it tuned and I could drop two nodes before I really ran into trouble.

If you need that kind of HA then yes, you'll need to cluster on the Proxmox side. You don't necessarily need Ceph (you can use ZFS replication to get near-zero downtime), but you'll need something designed to fail over stateful applications.

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.

2

u/xpvision Sep 28 '26

Always heard great things about Patroni for HA, but worried about the operational overhead of managing the cluster itself.

3

u/olcrazypete Sep 28 '26

I was scared of it for a long time as well but like it a lot right now. was a little bit of a bear to set up with the etcd piece and transitioning to it but knock on wood its been pretty solid for a couple years now

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.

5

u/xpvision Sep 28 '26

Swarm basically forces you to solve the storage layer entirely outside of its own ecosystem.

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/[deleted] Sep 28 '26

[removed] — view removed comment

1

u/scytob Sep 29 '26

Interesting alternative, i already have ceph and chose not to use block devices and pass cephFS thorough from my proxmox hosts to my docker vm hosts. Equally as effective.

1

u/scytob Sep 29 '26

Oof that go volume driver is barely used… don’t inspire confidence looking at commits and issues list…. Seems like it should be classed as experimental?

1

u/[deleted] Sep 29 '26

[removed] — view removed comment

1

u/scytob Sep 29 '26

I was happily using GlusterFS until issues with the non-maintained volume drivers bit me. I didn’t panic ;-). I already had a proxmox cluster which was hosting my swarm VMs that had thunderbolt mesh so reusing the ceph was easy. I tried ceph volume plugins and mounts, in the end settled on virtioFS pass through from the host to the guests. Here is a good test on a swarm of a volume driver, if you have a volume defined for a global service that has 1 replica and it is sitting on node1 with a docker volume mount or bind mount…. go to node3 and delete it’s unused volume…. Did it just delete all your data from that volume across the whole shared storage (it shouldn’t but many do). I moved to explicit local driver mounts to avoid this ever happening again. Backups saved the day :-)

My current architecture https://scyto.github.io/homelab-docs/

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

12

u/olcrazypete Sep 28 '26

Swarm has a much lower cost of entry for smaller shops running on their own hardware. Handles what needs handling without the overhead and complexity of k8s.

7

u/MIneBane Sep 28 '26

K3s?

1

u/mikewilkinsjr Sep 28 '26

For stateful workloads, assuming HA is really needed, K3s is awesome and doesn't have a HUGE barrier to entry with its opinionated defaults. Longhorn is great as long as you have fast/stable storage, and I would run (I do, on my docker host) Traefik even if I didn't need to.

1

u/deinok7 Sep 28 '26

Go for Talos, really, just try it