How does Docker Swarm handle database replication (PostgreSQL)?

I am learning Docker Swarm mode, and I was able to create Swarm locally using a web application and PostgreSQL database. I can scale them, and I see Roy creating replicas.

I think I understand how Docker Swarm can load the balance of regular web servers , but how does it deal with the box with database containers?

Out of context, usually Swarm databases handle replication in the form of plugins or advanced products such as a MySQL cluster . Other databases, such as Cassandra, have replication built directly into their product. In the context of Swarm, do we still need to rely on these plugins and database features?

What is the expected pattern for handling data consistency between replicas of a database container?

I know this is a very open question, but the Docker documentation is also very open, and I cannot find anything specific.

+6
source share
2 answers

How is this done out of the box with database containers?

This is not true.

There is a pretty good description of Swarm services here: How services work (highlighted by me)

When you deploy a service in a swarm, the swarm manager accepts your service definition as a necessary state for the service. He then assigns the service on the swarm nodes as one or more replica tasks.

Roy does not know that inside the task, all she knows is how many instances of this are, whether these instances check their health checks, and if they are enough to satisfy the task you gave him. The word overlap between this and database replicas is a bit unfortunate, but they are different concepts.

What is the expected pattern for handling data consistency between replicas of a database container?

Set up data replication for you. This is probably the right place to start, like any

+6
source

The docker swarm currently scales well for stateless applications. For database replication, you must rely on each mechanism for your own database replication. Roy could not control data replication. Volume or file system level replication can provide security for a single instance database, but is not aware of database replication / clustering.

Databases such as PostgreSQL require additional work. There are several options:

  • Use the local host directory. You will need to create one service for each replica and use constraint to schedule the container to one specific host. You will also need a custom postgresql docker image to configure postgresql replication among replicas. So far, when one node is omitted, one PostgreSQL replica will decline. You will need to work to raise another cue. See the crunchydata example .

  • Use a volume plugin like flocker , REX-Ray . You still need to create one service for each replica and map one volume to one service. You need to create all the services on the same overlay network and configure PostgreSQL replicas to talk to each other using the dns name (docker service name for the replica). You still need to configure postgresql replication among the replicas.

0
source

Source: https://habr.com/ru/post/1011993/


All Articles