-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.sh
47 lines (41 loc) · 995 Bytes
/
db.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
#!/usr/bin/env bash
CONTAINER_NAME='pg-error-snippet'
DATABASE='pg_error_snippet'
USER='postgres'
PASSWORD='postgres'
HOST='localhost'
PORT=5432
function startDocker() {
if [ $(docker ps -q -a -f name=$CONTAINER_NAME) ]; then
echo "Starting Postgres docker container"
docker start $CONTAINER_NAME
else
echo "Installing Postgres docker container"
docker run \
--detach \
--name $CONTAINER_NAME \
--publish "$PORT:5432" \
--env POSTGRES_USER=$USER \
--env POSTGRES_PASSWORD=$PASSWORD \
--env POSTGRES_DB=$DATABASE \
postgres:12
fi
}
function stopDocker() {
echo "Stopping Postgres docker container"
docker stop $CONTAINER_NAME
}
function destroyDocker() {
echo "Destroying Postgres docker container"
docker rm $(docker stop $CONTAINER_NAME)
}
function usage() {
echo "Usage: docker <start|stop|destroy>"
exit 1
}
case "$1" in
start) startDocker;;
stop) stopDocker;;
destroy) destroyDocker;;
*) usage;;
esac