Home > Blockchain >  Script to push an pull all images from nexus to harbor
Script to push an pull all images from nexus to harbor

Time:09-29

i want to push from nexus all images and pull them in harbor i try to do that

"- docker login -u -p https://harbor.domaine.com/

  • docker tag nexus.domaine.com/tag:number harbor.domaine.com/project_name/tag:number "

but the problem is that i have a lot of images and if i do this operation i need to write 1 ligne for every images so i want something like a loop too push all images from nexus any helm ?!

CodePudding user response:

You can try use bash script, for example

#!/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

CodePudding user response:

I've been developing 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 in the project itself.

To implement, create a 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

And then run regsync:

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