1、相关资源导航
https://blog.csdn.net/zyj81092211/article/details/123068347
2、环境介绍
操作系统:Centos 7.9
docker版本:20.10.17
私有仓库:harbor
工具:shell、skopeo
3、安装skopeo
(1)下载源码包
https://github.com/containers/skopeo/releases
wget https://github.com/containers/skopeo/archive/refs/tags/v1.9.2.tar.gz
tar -xvf v1.9.2.tar.gz
(2)安装go-md2man并获取程序目录
https://centos.pkgs.org/7/epel-aarch64/golang-github-cpuguy83-go-md2man-1.0.4-5.el7.aarch64.rpm.html
rpm -ivh https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/g/golang-github-cpuguy83-go-md2man-1.0.4-5.el7.x86_64.rpm
whereis go-md2man
(3)进入skopeo目录,进行容器编译
docker run -v $PWD:/src -v /usr/bin/go-md2man:/go/bin/go-md2man -w /src -e CGO_ENABLED=0 golang make BUILDTAGS=containers_image_openpgp GO_DYN_FLAGS=
(4)运行skopeo执行文件
bin/skopeo -v
(5)移动软件目录到/usr/local下,并创建bin文件软连接
mv skopeo-1.9.2/ /usr/local/skopeo
ln -s /usr/local/skopeo/bin/skopeo /usr/local/bin/skopeo
)
(6)编译后的bin文件分享
编译未成功的可以试试这个
https://download.csdn.net/download/zyj81092211/86501240
4、skopeo命令
skopeo login --tls-verify=false -u xxx -p xxx harbor.wtown.com
推送一个镜像
skopeo copy --insecure-policy --src-tls-verify=false --dest-tls-verify=false docker://docker.io/mysql:8.0.30-oracle docker://harbor.wtown.com/wtown/mysql:8.0.30-oracle
仓库中已有
5、创建同步脚本
vi /usr/local/bin/autoimagesync
添加如下(更换私有仓库信息)
set -e
input_info=$1
source_image_name=`echo $input_info | awk -F ':' '{ print $1 }'`
destination_image_name=`echo $input_info | awk -F ':' '{ print $1 }' | awk -F '/' '{ print $NF }'`
image_tag=`echo $input_info | awk -F ':' '{ print $2 }'`
if [ ! -n "$image_tag" ]; then
echo "未输入TAG,使用默认latest"
image_tag=latest
else
echo 'TAG是$image_tag'
fi
#定义私有仓库信息
harbor_registry='harbor.wtown.com'
project='wtown'
user='xxx'
password='xxx'
echo "登陆私有仓库..."
skopeo login --tls-verify=false -u ${user} -p ${password} ${harbor_registry}
if [[ $? -eq 0 ]] ;then
echo "登陆成功成功!!!"
fi
echo "开始同步镜像..."
skopeo copy --insecure-policy --src-tls-verify=false --dest-tls-verify=false docker://docker.io/${source_image_name}:${image_tag} docker://${harbor_registry}/${project}/${destination_image_name}:${image_tag}
if [[ $? -eq 0 ]] ;then
echo "镜像同步成功!!!"
fi
添加执行权限
chmod +x /usr/local/bin/autoimagesync
测试如下