Postgres container root or postgres user?

OSX: 10.12.3
Docker: Version 17.03.1-ce-rc1-mac3 (15924)
Channel: edge
Comunity Edition


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/ /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/ /docker-entrypoint-initdb.d
RUN chmod +x /docker-entrypoint-initdb.d/

RUN mkdir -p /var/lib/postgresql-static/data
ENV PGDATA /var/lib/postgresql-static/data

#!/usr/bin/env bash
# Tunnelling. Assume your host has an authorized_keys registered with portal
ssh -M -S my-ctrl-socket -fnNT -L 2000:

# 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

# Terminate tunnelling
ssh -S my-ctrl-socket -O exit

# 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


  1. postgres user unable to login to production server
  2. When I replace postgres user to root user. Container download only first database not apscheduler database

Am I misuse the /docker-entrypoint-initdb.d?