Created
August 10, 2016 22:52
-
-
Save ivanalejandro0/d697dc7aaf3b7987c297be35e5f876c9 to your computer and use it in GitHub Desktop.
PostgreSQL 9.5 script to run a dockerized psql locally.
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/sh | |
# file: docker-entrypoint-initdb.d/copy-config.sh | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
cp $SCRIPT_DIR/postgresql.conf /var/lib/postgresql/data/postgresql.conf |
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
# file: docker-entrypoint-initdb.d/postgresql.conf | |
listen_addresses = '*' | |
log_timezone = 'GMT' | |
timezone = 'GMT' |
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 | |
IMG="postgres:9.5" | |
NAME="postgresql-local" | |
start_fg() { | |
mkdir -p volumes/{data,shared} # create it to give myself write access | |
docker run --name $NAME -it --rm \ | |
--volume `pwd`/volumes/data:/var/lib/postgresql/data \ | |
--volume `pwd`/volumes/shared:/shared \ | |
--volume `pwd`/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d \ | |
--volume /var/run/postgresql:/var/run/postgresql \ | |
--env POSTGRES_PASSWORD=random-password-here \ | |
--publish 5432:5432 \ | |
$IMG | |
} | |
run() { | |
docker exec -i $NAME gosu postgres $@ | |
} | |
shell() { | |
docker exec -it $NAME gosu postgres bash | |
} | |
if [[ -z $1 ]]; then | |
start_fg | |
else | |
if [[ $1 == "bash" ]]; then shell; exit; fi; | |
run $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment