Skip to content

Instantly share code, notes, and snippets.

@ivanalejandro0
Created August 10, 2016 22:52
Show Gist options
  • Save ivanalejandro0/d697dc7aaf3b7987c297be35e5f876c9 to your computer and use it in GitHub Desktop.
Save ivanalejandro0/d697dc7aaf3b7987c297be35e5f876c9 to your computer and use it in GitHub Desktop.
PostgreSQL 9.5 script to run a dockerized psql locally.
#!/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
# file: docker-entrypoint-initdb.d/postgresql.conf
listen_addresses = '*'
log_timezone = 'GMT'
timezone = 'GMT'
#!/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