Yes, it is possible to implement volume replication and failover for a Docker Postgres database in a Docker Swarm environment, and to achieve high availability and scalability.
Here’s a sample example:
Create an NFS server: Set up an NFS server on a separate machine or virtual machine. The NFS server will provide a shared file system that is accessible from all nodes in the Swarm cluster.
Create a network: Create a network in Docker Swarm that will be used by the Postgres database containers.
Create a volume: Create a volume in Docker Swarm that will be used to store the Postgres database data. The volume will be backed by the NFS file system.
Test failover: To test failover, stop or remove a node in the Swarm cluster that is running the Postgres database container. The Swarm manager will automatically start a new instance of the container on another node, and the NFS file system will ensure that the data is available to the new container.