尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Linux shell 脚本案例:docker push 批量推送镜像

Linux shell 脚本案例:docker push 批量推送镜像 方法1使用 while 循环推荐dockerimages|grep192.168.0.95:5000/mes/nginx|awk{print $1:$2}|whilereadimage;doechoPushing$image...dockerpush$imageif[$?-eq0];thenecho✓ Successfully pushed$imageelseecho✗ Failed to push$imagefiecho---done方法2使用 xargs 并行推送更快dockerimages|grep192.168.0.95:5000/mes/nginx|awk{print $1:$2}|xargs-P3-I{}sh-cecho Pushing {} ... docker push {} echo ✓ Successfully pushed {} || echo ✗ Failed to push {}方法3单行简洁版dockerimages|grep192.168.0.95:5000/mes/nginx|awk{print $1:$2}|xargs-n1dockerpush方法4带进度显示和错误处理#!/bin/bashechoStarting to push images...count0failed0dockerimages|grep192.168.0.95:5000/mes/nginx|awk{print $1:$2}|whilereadimage;do((count))echo[$count] Pushing$image...ifdockerpush$image21;thenecho[$count] ✓ Successelseecho[$count] ✗ Failed((failed))fidoneecho---echoTotal:$countimages processedechoFailed:$failedimages注意事项方法1是最安全的会逐个推送并显示详细结果方法2使用-P 3可以并行推送3个镜像提高效率但需要确保网络和仓库能承受并发方法3最简单但错误处理较少如果镜像仓库需要认证请先执行docker login 192.168.0.95:5000建议先使用方法1进行测试确认没有问题后再使用并行推送提高效率。
返回列表