How to copy a docker image from one registry to another

 
 
  • Gérald Barré

Moving a docker image from one registry to another one can be useful to migrate images between different environments, for instance between staging and production. In this post, I describe how to copy a docker image from one registry to another using buildx.

An easy way would be to use the following commands:

Shell
# ⚠️ Don't use this method if you have a multi-platform image
docker pull myregistry1.com/image:tag
docker tag myregistry1.com/image:tag myregistry2.com/image:tag
docker push myregistry2.com/image:tag

However, there is drawbacks:

  • Only preserve a single architecture. If the image is a multi-platform image, you would lose the other platforms.
  • Performance: It pulls all layers to the docker engine, even if the other registry already have some of them.

Recently, docker introduced a new feature called buildx, which is a CLI plugin that extends the docker command with the full support of the features provided by Moby BuildKit builder toolkit. One of the features of buildx is the ability to copy images between registries.

Shell
docker buildx imagetools create --tag "myregistry2.com/image:tag" "myregistry1.com/image:tag"

Another solution is to use a lightweight tool that use the docker registry API to copy the image. One of the tools that can be used is skopeo or regctl.

Shell
regctl image copy source_image:tag target_image:tag
Shell
skopeo copy --all docker://source_image:tag docker://target_image:tag

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub