赞
踩
/data/harbor/harbor.yml
中的Hostname为本机IP地址,执行docker-compose down卸载再执行重新./install.sh安装HarborGithub: image-syncer
以下使用Docker来运行image-syncer,防止影响宿主机的host解析
wget https://github.com/AliyunContainerService/image-syncer/releases/download/v1.3.1/image-syncer-v1.3.1-linux-amd64.tar.gz
tar xf image-syncer-v1.3.1-linux-amd64.tar.gz
rm -f LICENSE README.md
# 获得帮助信息
./image-syncer -h
# 设置配置文件为config.json,默认registry为registry.cn-beijing.aliyuncs.com
# 默认namespace为ruohe,并发数为6
./image-syncer --proc=6 --auth=./auth.yaml --images=./images.yaml --retries=3
docker pull ubuntu
docker run -d --name image-syncer ubuntu tail -f /dev/null
docker cp image-syncer image-syncer:/root
docker exec -it image-syncer bash
apt update
apt -y install vim curl
# 将源Harbor解析添加到hosts中
echo '10.0.0.10 test.harbor.com' >> /etc/hosts
touch run.sh 10.0.0.11
chmod +x run.sh
#!/bin/bash
harbor_domain_name="test.harbor.com"
images_path=./images.yaml
auth_path=./auth.yaml
# 保存镜像列表到文件且文件名为IP地址,会自动遍历所有文件名为IP地址的文件
function if_ip_domain() {
code=$(curl -o /dev/null -k -s -u admin:Harbor12345 -w %{http_code} https://$1/health)
[ "$code" -eq 200 ] && return 0 || return 1
# docker login $1 -u admin -p Harbor12345 &> /dev/null
# [ $? -eq 0 ] && return 0 || return 1
}
>$auth_path
for i in $(ls -1); do
if if_ip_domain $i; then
file_image_list=$file_image_list" "$i
for authIP in $(cat $i | grep -E "^[^@#%^&*()/<>,;:'\"]+/[^@#%^&*()/<>,;:'\"]+/.*:[^@#%^&*()/<>,;:'\"]*[[:space:]]*$" | grep -Eo "^[^@#%^&*()/<>,;:'\"]+" | sort | uniq); do
echo ${authIP}: >>$auth_path
cat <<EOF >>$auth_path
username: admin
password: Harbor12345
insecure: true
EOF
done
echo ${i}: >>$auth_path
cat <<EOF >>$auth_path
username: admin
password: Harbor12345
insecure: true
EOF
fi
done
>$images_path
for i in $file_image_list; do
for line in $(cat $i | grep -E "^[^@#%^&*()/<>,;:'\"]+/[^@#%^&*()/<>,;:'\"]+/.*:[^@#%^&*()/<>,;:'\"]*[[:space:]]*$"); do
src=$line
dest=$(echo $src | sed -n 's/'$harbor_domain_name'/'$i'/p')
echo $src: $dest >>$images_path
done
done
>sync.log
# ./image-syncer --auth $auth_path --images $images_path -r 3 --log sync.log
./image-syncer --auth $auth_path --images $images_path -r 3 | tee sync.log
test.harbor.com/library/test01:v2.01.7
test.harbor.com/library/test02:v1.0.11
注意10.0.0.11是文件名,run.sh将会遍历文件名为10.0.0.11所有行,将镜像从test.harbor.com(10.0.0.10)推送到10.0.0.11
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。