forked from k19810703/EasyWebAutomation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.sh
43 lines (38 loc) · 1.24 KB
/
db_init.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
#!/usr/bin/env bash
modulename="db"
containername="webautodb"
echo "containername:"$containername
imagename=$containername"image"
echo "imagename:"$imagename
if docker ps -a | grep -q $containername ; then
echo $modulename" container exist";
docker stop $containername
echo $modulename" container stoped"
docker rm $containername
echo $modulename" container deleted"
else
echo $modulename" container does not exist";
fi
if docker images | grep -q $imagename ; then
echo $modulename" image exist";
docker rmi $imagename
echo $modulename" image deleted"
else
echo $modulename" image does not exist";
fi
docker build -t $imagename ./database/
if docker images | grep -q $imagename ; then
echo $modulename" image created"
#数据库端口3307可自行修改
docker run --name $containername -e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 -d $imagename
if docker ps -a | grep -q $containername ; then
echo $modulename" container created"
echo $modulename" wait 30s for mysql service fully started"
sleep 30
docker exec -it webautodb bash init.sh
else
echo "error: "$modulename" container was not created"
fi
else
echo "error: "$modulename" image was not created"
fi