-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker_run_postgres
More file actions
executable file
·65 lines (52 loc) · 1.26 KB
/
Copy pathdocker_run_postgres
File metadata and controls
executable file
·65 lines (52 loc) · 1.26 KB
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
#!/usr/bin/env bash
set -e
usage="$(basename "$0") [OPTIONS] VERSION
Runs the given VERSION of postgres using a docker container.
The container is named using the pattern \"postgres-VERSION\",
and will be created if it does not already exist.
options:
--fresh create the container afresh, removing any existing containers with the same name
--help show this help text"
options=$(getopt -o , --long help,fresh, -- "$@") || exit
eval set -- "$options"
fresh= # set to nothing
while true; do
case "$1" in
--help)
echo "$usage"
exit
;;
--fresh)
fresh=true
shift 1
;;
--)
shift
break
;;
*)
echo "Unknown option"
exit 1
;;
esac
done
version=${1:-'first argument must be postgres version'}
name="postgres-$version"
if [ "$fresh" ] && [ "$(docker ps -aq -f name="$name")" ]; then
echo "removing existing container named $name"
docker stop "$name"
docker rm "$name"
fi
if [ "$(docker ps -q -f name="$name")" ]; then
echo "a container with the name $name is already running"
exit 1
fi
if [ ! "$(docker ps -aq -f name="$name")" ]; then
docker create \
--name "$name" \
-e "POSTGRES_HOST_AUTH_METHOD=trust" \
-p 5432:5432 \
postgres:"$version"
fi
docker start "$name"
docker logs "$name" -f