将所有图像从 nexus 推送和拉取到 harbor 的脚本

Script to push and pull all images from nexus to harbor

我想从 nexus 中提取所有图像并将它们推送到 harbor 我尝试这样做

但问题是我有很多图像,如果我执行此操作,我需要为每个图像写 1 行,所以我想要类似循环的东西,也需要从 nexus 拉和推所有图像有帮助吗?!

您可以尝试使用 bash 脚本,例如

#!/bin/bash
docker login -u -p https://harbor.domaine.com/
for image_name in $(docker images --format="{{.Repository}}:{{.Tag}}" | grep nexus.domaine.com)
do
  new_image_name=$(echo $image_name | sed 's/nexus.domaine.com/harbor.domaine.com\/project_name/')
  docker tag $image_name $new_image_name
  docker push $new_image_name
done

我一直在开发 regsync to do exactly this. For a quick start, there's a workshop I recently gave at the docker all-hands, which includes not only the copy, but also the cleanup steps, or there's the quick start 项目本身。

要实现,创建一个 regsync.yml:

version: 1
creds:
  - registry: nexus.domaine.com
    # credentials here
  - registry: harbor.domaine.com
    # credentials here
defaults:
  parallel: 2
  interval: 60m
sync:
  - source: nexus.domaine.com/image
    target: harbor.domaine.com/project_name/image
    type: repository

然后 运行 重新同步:

docker container run -it --rm \
  -v "$(pwd)/regsync.yml:/home/appuser/regsync.yml:ro" \
  regclient/regsync:latest -c /home/appuser/regsync.yml once