5

Previously using Container Registry one could copy a container between projects using this method

However I am unable to get this working using Artifact Registry. If I try

gcloud artifacts docker tags add \
        us-east4-docker.pkg.dev/source-proj/my-repo/my-image:latest \
        us-east4-docker.pkg.dev/dest-proj/my-repo/my-image:latest

It gives the error

ERROR: (gcloud.artifacts.docker.tags.add) Image us-east4-docker.pkg.dev/source-proj/my-repo/my-image
does not match image us-east4-docker.pkg.dev/dest-proj/my-repo/my-image

I have searched and can not find any examples or documentation on how to do this.

Gourav B
  • 864
  • 5
  • 17
rossco
  • 593
  • 12
  • 22
  • Maybe the way to think about it is that each project has its own registry and then use: https://stackoverflow.com/questions/49976188/copy-docker-image-between-repositories – Kolban Oct 15 '21 at 03:28
  • Yes that is a work-around and what I have done for the time-being, I'm just hoping there is a convienient method like there previously was – rossco Oct 15 '21 at 03:32
  • @rossco Can you refer to the link : https://cloud.google.com/artifact-registry/docs/reference/docker-api and https://cloud.google.com/artifact-registry/docs/docker/pushing-and-pulling Is it helpful? – Divyani Yadav Oct 15 '21 at 12:21

2 Answers2

2

This can be done using gcrane cp us-east4-docker.pkg.dev/source-proj/my-repo/my-image:latest us-east4-docker.pkg.dev/dest-proj/my-repo/my-image:latest

James
  • 451
  • 2
  • 5
  • How can the above command be run since source-proj and dest-proj belong to different accounts and at a time GCP allows you to login into One account . Is there any way to download all the artifactory images from one account and push to another project account – shirish sahu Mar 30 '23 at 01:48
  • 1
    @shirishsahu - An IAM identity (user and service account) can be authorized for more than one project at the same time. – John Hanley Mar 30 '23 at 02:02
2

You can use the gcrane tool to copy images in Artifact Registry.

For example, the following command copies image my-image:latest from the repository my-repo in the project source-proj to the repository my-repo in another project called dest-proj.

gcrane cp \
    us-east4-docker.pkg.dev/source-proj/my-repo/my-image:latest \
    us-east4-docker.pkg.dev/dest-proj/my-repo/my-image:latest

Here is the link to the Google Cloud official documentation.

Gourav B
  • 864
  • 5
  • 17
  • This works beautifuly! I found the go installation found on the [github README](https://github.com/google/go-containerregistry/blob/main/cmd/gcrane/README.md) to work better on my Mac. – craastad Apr 12 '22 at 01:03
  • How can the above command be run since source-proj and dest-proj belong to different accounts and at a time GCP allows you to login into One account . Is there any way to download all the artifactory images from one account and push to another project account – shirish sahu Mar 30 '23 at 01:48