Uninote
Uninote

任务详情

任务链接地址

任务过程

#!/bin/bash
#================
# You need run "pip3 install runlike" first executed, make sure your machine have runlike command.
#================
#save all container
containers=()
#save container ip
ips=()
#save all container run args
runs=()
images=()

for container in $(docker ps|awk '{print $2","$NF}'|grep -iv names);do
    con=$(echo "$container"|awk -F ',' '{print $2}')
    im=$(echo "$container"|awk -F ',' '{print $1}')

    images[${#images[@]}]="$im"
    containers[${#containers[@]}]="$con"
    ips[${#ips[@]}]=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $con)
    runs[${#runs[@]}]=$(runlike $con|sed -r 's#--label=.*--#--#g')

done

subnet=$(ip addr|grep docker0|grep -o '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]/[[:digit:]]*'|sed -r 's#(.*\.)[[:digit:]]*/([[:digit:]]*)#\10/\2#')

# nework edit
yum -y install bridge-utils
systemctl stop docker
\cp /etc/docker/daemon.json{,.back}
echo '{' > /etc/docker/daemon.json
echo '"bip": "172.252.0.1/16",' >> /etc/docker/daemon.json
echo '"mtu": 1500' >> /etc/docker/daemon.json
echo '}' >> /etc/docker/daemon.json
ip link set dev docker0 down
brctl delbr docker0
systemctl start docker

# debug
docker network rm  dajxbridge
docker network create --subnet=$subnet dajxbridge

for ((index=0;index<${#containers[@]};index++));do

    containerName="${containers[$index]}"
    staticIp="${ips[$index]}"
    runCommand="${runs[$index]}"
    im=${im[$index]}

    docker stop "$containerName"
    # commit container
    docker commit "$containerName" "$containerName":staticIp
    # remove container
    docker rm -f "$containerName"
    # run container
    echo "$runCommand"|grep '\-t'
    res=$(echo $?)
    if [ $res -ne 0 ];then
        extraArgs=\ --network\ dajxbridge\ --ip\ "$staticIp"\ "$containerName":staticIp
        runCommand=$(echo "$runCommand"|sed -r "s# $im #$extraArgs #")
    else
        extraArgs=\ --network\ dajxbridge\ --ip\ "$staticIp"\ -itd\ "$containerName":staticIp\ bash
        runCommand=$(echo "$runCommand"|awk -F '-t' '{print $1}')"$extraArgs"
    fi
    $runCommand

    if [ $? -ne 0 ];then
        echo $runCommand
    fi

done

pm2进程管理实践

查找系统的大文件

点赞(0) 阅读(10) 举报
目录
标题