Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Dockerfile
- FROM postgres:9.6-alpine
- ENV GOSU_VERSION 1.10
- RUN set -ex;
- apk add --no-cache --virtual .gosu-deps
- dpkg
- gnupg
- openssl
- ;
- dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')";
- wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch";
- wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc";
- # verify the signature
- export GNUPGHOME="$(mktemp -d)";
- gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4;
- gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu;
- rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc;
- chmod +x /usr/local/bin/gosu;
- # verify that the binary works
- gosu nobody true;
- apk del .gosu-deps
- RUN apk add --update iputils
- RUN apk add --update htop
- # COPY ./setup-slave.sh /docker-entrypoint-initdb.d
- COPY ./docker-entrypoint.sh /docker-entrypoint.sh
- RUN chmod +x /docker-entrypoint.sh
- CMD ["gosu", "postgres", "pg_ctl", "-D/var/lib/postgresql/data", "start"]
- #!/bin/bash
- if [ ! -s "$PGDATA/PG_VERSION" ]; then
- echo '*:*:*:myuser:123456' > ~/.pgpass
- chmod 0600 ~/.pgpass
- until ping -c 1 -W 1 pg_master
- do
- echo "Waiting for master to ping..."
- sleep 1s
- done
- until pg_basebackup -h pg_master -D ${PGDATA} -U arioo -vP -W
- do
- echo "Waiting for master to connect..."
- sleep 1s
- done
- echo "host replication all 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf"
- set -e
- cat >> ${PGDATA}/postgresql.conf <<EOF
- wal_level = hot_standby
- max_wal_senders = 8
- wal_keep_segments = 32
- hot_standby = off
- EOF
- cat > ${PGDATA}/recovery.conf <<EOF
- standby_mode = on
- primary_conninfo = 'host=pg_master port=5432 user=rep password=123456'
- trigger_file = '/tmp/touch_me_to_promote_to_me_master'
- EOF
- chown postgres. ${PGDATA} -R
- chmod 700 ${PGDATA} -R
- fi
- exec "$@"
- while true; do
- sleep 1s
- done
Add Comment
Please, Sign In to add comment