批量配置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/24@192.168.0.110 ;done

导出镜像和还原

1)基于Docker commit将容器提交成镜像列表;

2)基于Docker save将镜像列表ID导出备份为tar包;

docker save ID >centos68.tar

3)基于Docker load 将镜像文件导入镜像列表

docker load <centos68.tar

4)通过Docker export导出容器成为镜像

docker export ID >centos68.tar

5)通过Docker import 导入容器成为镜像

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