说明:
多个tomcat容器,同时启动和关闭,每个docker容器的网络管理使用pipework控制.此脚本用来管理多个容器的创建,删除,启动和关闭.使用者可自行修改.
#!/bin/bash # chkconfig:2345 11 90 # description: Docker $Name BEGIN=1 END=4 Name=api Host="$Name" Mem=2048m Container_web_DIR="/tomcat/webapps" Container_log_DIR="/tmp" Host_web_DIR="/opt/docker/$Name/web" Host_log_DIR="/opt/docker/$Name/log" IOS="192.168.0.136:5000/singulax/tomcat:7.0.55.1" Net="172.17.6" GATEWAY="$Net.254" create(){ for ((n=BEGIN;n<=END;n++)) do 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 docker exec -it $Name$n ifconfig eth0 down /usr/local/bin/pipework docker0 -i eth1 $Name$n $Net.$n/[email protected]$GATEWAY done } delete(){ for ((n=BEGIN;n<=END;n++)) do docker stop $Name$n && docker rm $Name$n done } start(){ for ((n=BEGIN;n<=END;n++)) do docker start $Name$n docker exec -it $Name$n ifconfig eth0 down /usr/local/bin/pipework docker0 -i eth1 $Name$n $Net.$n/[email protected]$GATEWAY done } stop(){ for ((n=BEGIN;n<=END;n++)) do docker stop $Name$n done } case $1 in create) echo "Creating $Name Containner for $Name Docker Service" create ;; delete) echo "Deleting $Name Containner for $Name Docker Service" delete ;; start) echo "Start running $Name Containner" start ;; stop) echo "Stop running $Name Containner" stop ;; *) echo $"Usage: $0 {start|stop|create|delete}" exit 1 ;; esac
时间: 2024-10-08 21:31:43