OSX: 10.12.3
Docker: Version 17.03.1-ce-rc1-mac3 (15924)
Channel: edge
1795b358d5
Comunity Edition
DockerFile
FROM postgres:9.5
# Install hstore extension
COPY ./dockerfiles/hstore.sql /docker-entrypoint-initdb.d
# Copy authorized key
RUN apt-get update && apt-get install -y openssh-client
RUN mkdir -p /home/postgres
RUN mkdir -p /home/postgres/.ssh
# Can not anything outside the project directory
COPY ./dockerfiles/id_rsa /home/postgres/.ssh
COPY ./dockerfiles/id_rsa.pub /home/postgres/.ssh
COPY ./dockerfiles/known_hosts /home/postgres/.ssh
# Private key must be 700
RUN chmod 700 /home/postgres/.ssh/id_rsa
# Download production database into docker development postgres by using script
COPY ./dockerfiles/prepare_db.sh /docker-entrypoint-initdb.d
RUN chmod +x /docker-entrypoint-initdb.d/prepare_db.sh
RUN mkdir -p /var/lib/postgresql-static/data
ENV PGDATA /var/lib/postgresql-static/data
prepare_db.sh
#!/usr/bin/env bash
# Tunnelling. Assume your host has an authorized_keys registered with portal
ssh -M -S my-ctrl-socket -fnNT -L 2000:10.134.5.6:5432 root@prodction.com
# Download production database. Although I know how to pip the I/O directly to my docker
# I myself prefer intermediate file. I can cross check you storage capacity before hand
pg_dump -U uih -d uih_portal -h localhost -p 2000 > uih_portal.sql
pg_dump -U uih -d apscheduler -h localhost -p 2000 > apscheduler.sql
# Check my established socket
ssh -S my-ctrl-socket -O check root@production.com
# Terminate tunnelling
ssh -S my-ctrl-socket -O exit root@portal.uih.co.th
# Restore database
psql -U uih -d uih_portal -h localhost -p 5432 < uih_portal.sql
# Seems like 2nd database instance is not automatic created by simple dumpfile
#postgres_1 | psql: FATAL: database "apscheduler" does not exist
#postgres_1 | FATAL: database "apscheduler" does not exist
createdb -U uih apscheduler
psql -U uih -d apscheduler -h localhost -p 5432 < apscheduler.sql
# Remove intermediate file
rm uih_portal.sql
rm apscheduler.sql
Problem:
-
postgres
user unable to login to production server - When I replace
postgres
user toroot
user. Container download only first database notapscheduler
database
Am I misuse the /docker-entrypoint-initdb.d
?