How to copy a docker image from one registry to another

 
 
  • Gérald Barré

Moving a Docker image from one registry to another is useful when migrating images between environments, such as from staging to production. This post describes 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 are drawbacks:

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

Docker introduced a CLI plugin called buildx, which extends the docker command with full support for the features provided by the Moby BuildKit builder toolkit. One of its features 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 interacts directly with the Docker registry API to copy images. Options include skopeo and 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?