批量配置IP
for i in `docker ps -a|awk 'NR>1 {print $NF}'`;do IP=`echo $i|awk -F_ '{print "192.168."$2"."$3}'`;pipework br0 $i $IP/[email protected] ;done
导出镜像
cat centos68.tar|docker import - centos68
docker import - centos68 < centos68.tar
配置IP地址
docker inspect wenle1 |grep -i address |awk '/([0-9]{1,3}\.){3}[0-9]{1,3}/ {print $NF}'|sed 's/"//g;s/,//g'|tail -1
获取容器ID
docker ps -a|grep "centos68"|awk '{print $1}'
获取ID容器容器IP,并且打印ID和IP信息
for ID in `docker ps -a|grep `centos68"|awk '{print $1}'`;do docker inspect $ID|grep -i ipaddr|awk '/([0-9]{1,3}\.){3}[0-9]{1,3}/ {print $NF}' |sed 's/"//g;s/,//g'|tail -1|awk '{print " '$ID' " $0}';done
[root@localhost ~]# for ID in `docker ps -a|grep "centos68"|awk '{print $1}'`;do docker inspect $ID |grep -i address |awk '/([0-9]{1,3}\.){3}[0-9]{1,3}/ {print $NF}'|sed 's/"//g;s/,//g'|tail -1|awk '{print "'$ID' " $0}';done|awk '{print NR,$0}'|sed 's/ /,/g' #增加行号,并将空格替换成,
[root@localhost ~]# for ID in `docker ps -a|grep "centos68"|awk '{print $1}'`;do docker inspect $ID |grep -i address |awk '/([0-9]{1,3}\.){3}[0-9]{1,3}/ {print $NF}'|sed 's/"//g;s/,//g'|tail -1|awk '{print "'$ID' " $0}';done|awk '{print NR,$0}'|sed 's/ /,/g'>docker_list.csv #导出到docker_list.csv
批量启动多台docker LAMP服务
for i in `docker ps -a|grep "centos68"|awk '{print $1}'` ;do for j in `echo sshd httpd mysqld ` ;do docker exec $i service $j restart ;done ;done
for i in `docker ps -a|grep "centos68"|awk '{print $1}'`;do docker exec $i service sshd restart;docker exec $i service httpd restart;docker exec $i service mysqld restart;done