-
Notifications
You must be signed in to change notification settings - Fork 4
/
start_docker.sh
executable file
·65 lines (55 loc) · 1.52 KB
/
start_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
#!/bin/bash
IMAGE_NAME='hogwarts'
BUILD_IMAGE=false
MIGRATE_DATABASE=false
SEED_DATABASE=true
APACHE_SERVERNAME=hogwarts.lan
APP_ENV=local # TODO Change
APP_DEBUG=true # TODO Change
APP_KEY=
DB_PORT=3306
DB_DATABASE=hogwarts
DB_USERNAME=hogwarts
DB_PASSWORD=1324
DB_DATA_DIR=
while [[ ! -z $1 ]]; do
case $1 in
'--build')
BUILD_IMAGE=true
;;
*)
DB_DATA_DIR="$1"
;;
esac
shift
done
if [[ -z $DB_DATA_DIR ]]; then
echo "Please give a directory for mysql database" >&2
exit 1
fi
if [[ -z $(docker images -q $IMAGE_NAME 2> /dev/null) ]] || $BUILD_IMAGE; then
docker build -t "$IMAGE_NAME" . || exit 1
fi
DB_CONTAINER=`docker run -d -p $DB_PORT:3306 \
-v "$DB_DATA_DIR:/var/lib/mysql" \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_ONETIME_PASSWORD=yes \
-e MYSQL_DATABASE="$DB_DATABASE" \
-e MYSQL_USER="$DB_USERNAME" \
-e MYSQL_PASSWORD="$DB_PASSWORD" \
mysql`
echo $DB_CONTAINER
DB_HOST=`docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $DB_CONTAINER`
docker run -i -d -p 80:80 \
-v /etc/localtime:/etc/localtime:ro \
-e APACHE_SERVERNAME="$APACHE_SERVERNAME" \
-e APP_ENV="$APP_ENV" \
-e APP_DEBUG="$APP_DEBUG" \
-e APP_KEY="$APP_KEY" \
-e DB_HOST="$DB_HOST" \
-e DB_PORT="$DB_PORT" \
-e DB_DATABASE="$DB_DATABASE" \
-e DB_USERNAME="$DB_USERNAME" \
-e DB_PASSWORD="$DB_PASSWORD" \
-e SEED_DATABASE="$SEED_DATABASE" \
"$IMAGE_NAME"