Dockerized Postgres Replication Slave Database as a service
1.2K
$ docker network create pgreplication_net
$ docker run -dit --name=postgres_slave \
--network=pgreplication_net \
-v slave_vol:/data/postgresql/12/rep \
-p 5433:5432 \
yurinek/postgres_slave:12
# Connect from host ( default password: mysecret )
$ psql -h localhost -p 5433 -U postgres mydb -W
psql: error: connection to server at "localhost" (::1), port 5433 failed: FATAL: no pg_hba.conf entry for host "192.168.65.1", user "postgres", database "mydb"
# if the above error happens, db access from local ip needs to be granted
docker container exec -it postgres_slave su - postgres -c "echo 'host all all 192.168.65.1/32 md5' >>/etc/postgresql/12/rep/pg_hba.conf"
docker container exec -it postgres_slave su - postgres -c "/usr/bin/pg_ctlcluster 12 rep reload"
$ export RUNTIME_ENV_PG_DB=yourdb
$ export POSTGRES_PASSWORD=yoursecret
$ export RUNTIME_ENV_MASTER_HOST=yourcontainername
$ docker run -dit --name=postgres_slave \
--network=pgreplication_net \
-e RUNTIME_ENV_PG_DB=$RUNTIME_ENV_PG_DB \
-e RUNTIME_ENV_MASTER_HOST=$RUNTIME_ENV_MASTER_HOST \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-v slave_vol:/data/postgresql/12/rep \
-p 5433:5432 \
yurinek/postgres_slave:12
# Connect from host
$ psql -h localhost -p 5433 -U postgres $RUNTIME_ENV_PG_DB -W
# Database name and password need to be the same as in master container
# Master host (container) name needs to be the same as $RUNTIME_ENV_MASTER_HOST, See yurinek/postgres_master
For Kubernetes tag 12_k8s can be used
Content type
Image
Digest
Size
108.8 MB
Last updated
over 6 years ago
docker pull yurinek/postgres_slave