forked from kartoza/docker-postgis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-postgis-docker.sh
executable file
·94 lines (78 loc) · 1.97 KB
/
run-postgis-docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Commit and redeploy the user map container
usage()
{
cat << EOF
usage: $0 options
This script runs a new docker postgis instance for you.
To get the image run:
docker pull kartoza/postgis
OPTIONS:
-h Show this message
-n Container name
-v Volume to mount the Postgres cluster into
-u Postgres user name (defaults to 'docker')
-p Postgres password (defaults to 'docker')
EOF
}
while getopts ":h:n:v:u:p:" OPTION
do
case $OPTION in
n)
CONTAINER_NAME=${OPTARG}
;;
v)
VOLUME=${OPTARG}
;;
u)
PGUSER=${OPTARG}
;;
p)
PGPASSWORD=${OPTARG}
;;
*)
usage
exit 1
;;
esac
done
if [[ -z $VOLUME ]] || [[ -z $CONTAINER_NAME ]] || [[ -z $PGUSER ]] || [[ -z $PGPASSWORD ]]
then
usage
exit 1
fi
if [[ ! -z $VOLUME ]]
then
VOLUME_OPTION="-v ${VOLUME}:/var/lib/postgresql"
else
VOLUME_OPTION=""
fi
if [ ! -d $VOLUME ]
then
mkdir $VOLUME
fi
chmod a+w $VOLUME
docker kill ${CONTAINER_NAME}
docker rm ${CONTAINER_NAME}
CMD="docker run --name="${CONTAINER_NAME}" \
--hostname="${CONTAINER_NAME}" \
--restart=always \
-e POSTGRES_USER=${PGUSER} \
-e POSTGRES_PASS=${PGPASSWORD} \
-d -t \
${VOLUME_OPTION} \
kartoza/postgis /start-postgis.sh"
echo 'Running\n'
echo $CMD
eval $CMD
docker ps | grep ${CONTAINER_NAME}
IPADDRESS=`docker inspect ${CONTAINER_NAME} | grep IPAddress | grep -o '[0-9\.]*'`
echo "Connect using:"
echo "psql -l -p 5432 -h $IPADDRESS -U $PGUSER"
echo "and password $PGPASSWORD"
echo
echo "Alternatively link to this container from another to access it"
echo "e.g. docker run -link postgis:pg .....etc"
echo "Will make the connection details to the postgis server available"
echo "in your app container as $PG_PORT_5432_TCP_ADDR (for the ip address)"
echo "and $PG_PORT_5432_TCP_PORT (for the port number)."