-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnt-create-mongo-server
executable file
·47 lines (36 loc) · 1.29 KB
/
cnt-create-mongo-server
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
# Variables used for the script
if [ ! -f `which pwgen` ]; then
echo "You must have pwgen on your machine to run this script"
exit 1
fi
if [ -z "$DKR_HOST_PORT" ]; then
echo "You must provide docker host port"
exit 1
fi
if [ -z "$DKR_CNT_NAME" ]; then
echo "You must provide dockercontainer name"
exit 1
fi
CMG_COMMAND=docker
DKR_IMAGE="percona/percona-server-mongodb"
DKR_HOST_PORT=$1
DKR_CNT_NAME=$2
DKR_DATA_PATH=dbcmgo-$DKR_CNT_NAME-dvol
DKR_MGO_USER=dkradmin
DKR_MGO_PASSWORD=`pwgen -1 16 | tr -d '\n'`
echo "Docker Image ............................ :'$DKR_IMAGE'"
echo "Database Admin User ..................... :'$DKR_MGO_USER'"
echo "Database Admin User Password ............ :'$DKR_MGO_PASSWORD'"
echo "Docker Volume Name ...................... :'$DKR_DATA_PATH'"
echo "Docker Host Port ........................ :'$DKR_HOST_PORT'"
echo "Docker Container Name ................... :'$DKR_CNT_NAME'"
$CMG_COMMAND run --name $DKR_CNT_NAME \
-p $DKR_HOST_PORT:27017 \
-e "MONGO_INITDB_ROOT_USERNAME=$DKR_MGO_USER" \
-e "MONGO_INITDB_ROOT_PASSWORD=$DKR_MGO_PASSWORD" \
-v $DKR_DATA_PATH:/data/db \
-d $DKR_IMAGE
echo "Waiting for container '$DKR_CNT_NAME' to start ... "
sleep 10
echo "Docker Container '$DKR_CNT_NAME' has been started on port '$DKR_HOST_PORT'"