释放双眼,带上耳机,听听看~!
说明:
多个tomcat容器,同时启动和关闭,每个docker容器的网络管理使用pipework控制.此脚本用来管理多个容器的创建,删除,启动和关闭.使用者可自行修改.
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
66 1#!/bin/bash
2# chkconfig:2345 11 90
3# description: Docker $Name
4BEGIN=1
5END=4
6Name=api
7Host="$Name"
8Mem=2048m
9Container_web_DIR="/tomcat/webapps"
10Container_log_DIR="/tmp"
11Host_web_DIR="/opt/docker/$Name/web"
12Host_log_DIR="/opt/docker/$Name/log"
13IOS="192.168.0.136:5000/singulax/tomcat:7.0.55.1"
14Net="172.17.6"
15GATEWAY="$Net.254"
16create(){
17 for ((n=BEGIN;n<=END;n++))
18 do
19 docker run -d --privileged --name $Name$n -h $Host$n -m $Mem --memory-swap=$Mem -v /etc/localtime:/etc/localtime -v $Host_web_DIR:$Container_web_DIR -v $Host_log_DIR:$Container_log_DIR $IOS
20 docker exec -it $Name$n ifconfig eth0 down
21 /usr/local/bin/pipework docker0 -i eth1 $Name$n $Net.$n/24@$GATEWAY
22 done
23}
24delete(){
25 for ((n=BEGIN;n<=END;n++))
26 do
27 docker stop $Name$n && docker rm $Name$n
28 done
29}
30start(){
31 for ((n=BEGIN;n<=END;n++))
32 do
33 docker start $Name$n
34 docker exec -it $Name$n ifconfig eth0 down
35 /usr/local/bin/pipework docker0 -i eth1 $Name$n $Net.$n/24@$GATEWAY
36 done
37}
38stop(){
39 for ((n=BEGIN;n<=END;n++))
40 do
41 docker stop $Name$n
42 done
43}
44case $1 in
45create)
46 echo "Creating $Name Containner for $Name Docker Service"
47 create
48;;
49delete)
50 echo "Deleting $Name Containner for $Name Docker Service"
51 delete
52;;
53start)
54 echo "Start running $Name Containner"
55 start
56;;
57stop)
58 echo "Stop running $Name Containner"
59 stop
60;;
61*)
62 echo $"Usage: $0 {start|stop|create|delete}"
63 exit 1
64;;
65esac
66