Created
September 11, 2017 06:10
-
-
Save shirou/e7a6706612ac0e815bf4a7316c6e203a to your computer and use it in GitHub Desktop.
docker postgres sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
postgres: | |
image: postgres:9.5.2 | |
volumes: | |
- $PWD/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d | |
ports: | |
- "45432:5432" | |
pgweb: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# docker-entrypoint-initdb.d/initial.sh | |
set -e | |
cp /docker-entrypoint-initdb.d/server.crt "$PGDATA"/server.crt | |
cp /docker-entrypoint-initdb.d/server.key "$PGDATA"/server.key | |
chown postgres:postgres "$PGDATA"/server.* | |
chmod 600 "$PGDATA"/server.* | |
cat <<EOF >> "$PGDATA"/postgresql.conf | |
ssl = on # (change requires restart) | |
ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers | |
# (change requires restart) | |
ssl_prefer_server_ciphers = on # (change requires restart) | |
ssl_ecdh_curve = 'prime256v1' # (change requires restart) | |
ssl_cert_file = '$PGDATA/server.crt' # (change requires restart) | |
ssl_key_file = '$PGDATA/server.key' # (change requires restart) | |
EOF | |
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL | |
CREATE USER hoge WITH PASSWORD 'hoge' SUPERUSER; | |
CREATE DATABASE "hogedb" OWNER hoge; | |
CREATE DATABASE "hogedb-test" OWNER hoge; | |
CREATE EXTENSION IF NOT EXISTS hstore; | |
ALTER DATABASE "hogedb" set timezone = 'Asia/Tokyo'; | |
ALTER DATABASE "hogedb-test" set timezone = 'Asia/Tokyo'; | |
EOSQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment