-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.sh
executable file
·57 lines (48 loc) · 1.12 KB
/
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
#!/usr/bin/env bash
set -e
if ! [ -x "$(command -v docker)" ]; then
echo docker is not installed 1>&2
exit 1
fi
datadir=$(mktemp -d)
rm -rf $datadir
img=mysql/mysql-server:${version:-8.0.27}
cname=mysql
mycnf=$(mktemp)
host=localhost
port=3406
user=root
password=dockword
if [[ "$OSTYPE" == "darwin"* ]]; then
: # docker for mac does not support sharing unix sockets
: # for details see: https://github.com/docker/for-mac/issues/483
: # on linux it works, so you can uncomment it
else
sock=${datadir}/mysql.sock
fi
echo +++ get default my.cnf
docker run --name $cname -d $img
docker cp $cname:/etc/my.cnf $mycnf
docker rm -f $cname
echo +++ docker run ${img}
env=(
-e MYSQL_ROOT_PASSWORD=$password # if not set, generates random onetime password
-e MYSQL_ROOT_HOST=% # allow root connections from other hosts
)
docker run \
--name $cname \
"${env[@]}" \
-v $mycnf:/etc/my.cnf \
-v $datadir:/var/lib/mysql \
-p $port:3306 \
-d $img
start_mysql() {
docker start $cname
}
stop_mysql() {
docker stop $cname
}
cleanup() {
docker rm -f $cname
rm -rf $mycnf
}