一、批量构建镜像
buildDockerImages.sh
#!/usr/bin/env bash
echo "==================== start build docker images =========================="
cd /www/docker/images/
old_IFS=$IFS
IFS=','
cmds=(
'docker build -t xxx-base-env .',
'docker build -t redis:3.2 -f redis.dockerfile .',
'docker build -t mysql:5.6 -f mysql.dockerfile .',
'docker build -t elasticsearch:5.6.5 -f es.dockerfile .',
'docker build -t openresty -f openresty.dockerfile .'
)
for cmd in ${cmds[*]};do
eval "$cmd"
done
IFS=$old_IFS
echo "==================== end build docker images =========================="
二、批量删除无用的镜像,保留有用的镜像
clearDockerImages.sh
#!/usr/bin/env bash
echo "==================== start clean docker images =========================="
docker images | awk '
NR>1{
if($1 == "xxx-base-env" ||
$1 == "mysql:5.6" ||
$1 == "mysql:5.7" ||
$1 == "redis:3.2" ||
$1 == "elasticsearch:5.6.5" ||
$1 == "openresty" ||
$1 == "monitoringartist/zabbix-xxl:3.2.6")
{
print "skiped ..."
}else{
system("docker rmi " $3)
}
}
';
echo "==================== end clean docker images =========================="
三、批量删除docker容器的log
clearDockerContainerLogs.sh
#!/usr/bin/env bash
echo "==================== start clean docker containers logs =========================="
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
echo "clean logs : $log"
cat /dev/null > $log
done
echo "==================== end clean docker containers logs =========================="
网友评论