generated from aceleradora-TW/template-de-projeto
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocker-db.sh
executable file
·51 lines (45 loc) · 1.41 KB
/
docker-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
48
49
50
51
#!/bin/bash
readonly CONTAINER_NAME=template-aceleradora-db
readonly POSTGRES_USER=postgres
readonly POSTGRES_PASSWORD=123456
readonly POSTGRES_IMAGE="postgres:12"
readonly DATABASE_NAME=descarte_certo
case $1 in
run-volatile)
docker run \
--rm \
--name ${CONTAINER_NAME} \
--publish 5432:5432 \
--env POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
--detach \
${POSTGRES_IMAGE}
;;
run-persistent)
mkdir -p ~/.pgsql/${CONTAINER_NAME}
docker run \
--rm \
--name ${CONTAINER_NAME} \
--volume ~/.pgsql/${CONTAINER_NAME}:/var/lib/postgresql/data \
--publish 5432:5432 \
--env POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
--detach \
${POSTGRES_IMAGE}
;;
create)
docker exec -it ${CONTAINER_NAME} psql -U ${POSTGRES_USER} -c "CREATE DATABASE ${DATABASE_NAME}"
;;
console)
docker exec -it ${CONTAINER_NAME} psql -U ${POSTGRES_USER} -d ${POSTGRES_PASSWORD}
;;
stop)
docker stop ${CONTAINER_NAME}
;;
*)
echo "Opcoes: "
echo -e "\t - run-volatile: Inicia container com volume de dados volatil (dados sao perdidos quando o container para)"
echo -e "\t - run-persistent: Inicia container com volume de dados persistente"
echo -e "\t - create: Cria banco de dados dentro do container"
echo -e "\t - console: Abre cliente postgres conectado ao container"
echo -e "\t - stop: Para execucao do container"
;;
esac