version: '3.9' volumes: pg-master-data-dir: pg-node-data-dir: services: pg-master: image: kartoza/postgis:14-3.2 restart: 'always' # You can optionally mount to volume, to play with the persistence and # observe how the slave will behave after restarts. volumes: - pg-master-data-dir:/var/lib/postgresql - ./scripts/setup-master.sql:/docker-entrypoint-initdb.d/setup-master.sql environment: # ALLOW_IP_RANGE option is used to specify additionals allowed domains # in pg_hba. # This range should allow slaves to connect to master ALLOW_IP_RANGE: '0.0.0.0/0' # We can specify optional credentials REPLICATION_USER: 'replicator' REPLICATION_PASS: 'replicator' REPLICATION: 'true' # Setup master replication variables #PG_MAX_WAL_SENDERS: 8 #PG_WAL_KEEP_SEGMENTS: 100 # You can expose the port to observe it in your local machine ports: - "7777:5432" healthcheck: test: "exit 0" pg-node: image: kartoza/postgis:14-3.2 restart: 'always' # You can optionally mount to volume, but we're not able to scale it # in that case. # The slave will always destroy its database and copy from master at # runtime volumes: - pg-node-data-dir:/var/lib/postgresql environment: # ALLOW_IP_RANGE option is used to specify additionals allowed domains # in pg_hba. # Not really needed in slaves for the replication, but optionally can # be put when slaves are needed to be a failover server when master # is down. The IP Range are generally needed if other services wants to # connect to this slave ALLOW_IP_RANGE: '0.0.0.0/0' # REPLICATE_FROM options accepts domain-name or IP address # with this in mind, you can also put docker service name, because it # will be resolved as host name. REPLICATE_FROM: 'pg-master' REPLICATION: 'true' # REPLICATE_PORT will default to 5432 if not specified. # REPLICATE_PORT: '5432' # In the case where you need to replicate from outside service, # you can put the server address and port here, as long as the target # where configured as master, and replicable. # REPLICATE_FROM: '192.168.1.8' # REPLICATE_PORT: '7777' # DESTROY_DATABASE_ON_RESTART will default to True if not specified. # If specified other than True, it will prevent slave from destroying # database on restart DESTROY_DATABASE_ON_RESTART: 'True' # PROMOTE_MASTER Default empty. # If specified with any value, then it will convert current slave into # a writable state. Useful if master is down and the current slave needs # to be promoted until manual recovery. #PROMOTE_MASTER: 'True' # For now we don't support different credentials for replication # so we use the same credentials as master's superuser, or anything that # have replication role. REPLICATION_USER: 'replicator' REPLICATION_PASS: 'replicator' depends_on: pg-master: condition: service_healthy # You can expose the port to observe it in your local machine # For this sample, it was disabled by default to allow scaling test ports: - "7776:5432"