Search code examples
dockerdocker-registrydockerhub

How to push image from private registry to hub.docker.com?


I'm migrating a project from a private registry to hub.docker.com but I don't have all tagged image on computer.

I have access to the registry machine via SSH.

Question

How can I push all my registry images to hub.docker.com?


Solution

  • I think that the only way is to pull them all, then retag them and push to hub.docker.com

    You can script it with something like:

    for repository in $(curl -s http://localhost:5000/v2/_catalog | jq -r '.repositories[]'); do
      for image in $(curl -s http://localhost:5000/v2/${repository}/tags/list | jq -r '(.name + ":" + .tags[])')
        docker image pull localhost:5000/${image}
        docker image tag localhost:5000/${image} <YOUR_HUB_PREFIX>/${image}
        docker image push <YOUR_HUB_PREFIX>/${image}
        # if you need some cleanup
        docker image rm localhost:5000/${image} <YOUR_HUB_PREFIX>/${image}
      done
    done