Creating postgres cluster in DOCKER SWARM
===standby/master=== docker service create --network your_network --name postgresql_1 --constraint node.hostname==your_node_hostname -e REPMGR_USER=repl -e REPMGR_DB=repldb -e REPMGR_PASSWORD=password -e PRIMARY_PORT=5432 -e PGPORT=5432 -e PRIMARY_NODE=(master node ip or hostname) -e PGPOOL_PORT=5430 --replicas 1 --publish published=5432,target=5432 --mount type=bind,source=/opt/postgresql_1,target=/var/lib/postgresql/data --mount type=bind,source=/opt/repmgr_1/repmgr.conf,target=/etc/repmgr.conf --env POSTGRES_PASSWORD=password deadsen/postgres:repmgr5-10
====standby/master==== docker service create --network your_network --name postgresql_2 --constraint node.hostname==your_node_hostname -e REPMGR_USER=repl -e REPMGR_DB=repldb -e REPMGR_PASSWORD=repmgrpass -e PRIMARY_PORT=5432 -e PGPORT=5432 -e PRIMARY_NODE=node1 -e PGPOOL_PORT=5430 --replicas 1 --publish published=5433,target=5432 --mount type=bind,source=/opt/postgresql_2,target=/var/lib/postgresql/data --mount type=bind,source=/opt/repmgr_2/repmgr.conf,target=/etc/repmgr.conf --env POSTGRES_PASSWORD=password deadsen/postgres:repmgr5-10
====Witness==== docker service create --network services --name postgresql_3 --constraint node.labels.type==arbiter --constraint node.hostname==your_node_hostname -e REPMGR_DB=repldb -e REPMGR_PASSWORD=repmgr_pass -e PRIMARY_PORT=5432 -e PGPORT=5432 -e WITNESS=1 -e PRIMARY_NODE=node1 -e PGPOOL_PORT=5430 --replicas 1 --publish published=5434,target=5432 --mount type=bind,source=/opt/postgresql_3,target=/var/lib/postgresql/data --mount type=bind,source=/opt/repmgr_3/repmgr.conf,target=/etc/repmgr.conf --env POSTGRES_PASSWORD=password deadsen/postgres:repmgr5-10
=============PGPOOL==================== docker service create --network services --name pgpool --replicas 1 -e BACKENDS="0:ip/hostname:pg_port:1:/var/lib/postgresql/data:ALLOW_TO_FAILOVER,1:ip/hostname:pg_port:1:/var/lib/postgresql/data:ALLOW_TO_FAILOVER" -e PCP_USER=pool -e PCP_PASSWORD='pcp_pass' -e WAIT_BACKEND_TIMEOUT=60 -e CHECK_USER=repl -e CHECK_PASSWORD='pass_from_repmgr' -e REQUIRE_MIN_BACKENDS=1 published=5430,target=5432 --publish 127.0.0.1:9898:9898 postdock/pgpool:latest-pgpool37-postgres1
Repo for docker build : https://github.com/deadsen/docker_postgres_repmgr
Useful links for postgres replication in docker :
https://github.com/paunin/PostDock https://blog.2ndquadrant.com/pg-phriday-getting-rad-docker-part-3
Content type
Image
Digest
Size
105.9 MB
Last updated
almost 6 years ago
docker pull deadsen/postgres:10-replication