Skip to content

Copy containers between repos

What

This is especially useful when moving from gcr.io to the new Artifact registry that Google offer.

That's not to say that you can't use this for copying between private repositories (as long as you're authenticated)

How

We can use a tool called gcrane

Install gcrane

go install github.com/google/go-containerregistry/cmd/gcrane@latest

This will build and install the package to your $PATH

List images

gcrane ls userbradley/searchsploit

We should see something similar to the below

index.docker.io/userbradley/searchsploit:alpine-0.0.1
index.docker.io/userbradley/searchsploit:alpine-0.0.2
index.docker.io/userbradley/searchsploit:alpine-base
index.docker.io/userbradley/searchsploit:ubuntu-0.0.1
index.docker.io/userbradley/searchsploit:ubuntu-1

Copy all images to AR

gcrane cp -r userbradley/searchsploit europe-west2.pkg.dev/bradley/searchsploit/searchsploit

External sources

Gcrane not working

Somtimes after running the command, it returns with nothing.

I cant explain why it does this, but it's annoying.

Create a file with all the images

gcrane ls userbradley/searchsploit > images.txt

Make sure to remove the index.docker.io/reponame/container at the start of the image, or it breaks

Create a script to copy them one after another

## copy.sh
#!/bin/bash

images=$(cat images.txt)

for img in ${images}
do
    gcrane cp userbradley/searchsploit:${img} europe-west2.pkg.dev/bradley/searchsploit/searchsploit:${img}
done

The reason we specify the image name in the script is because when I was running it, it was copying the containers but not the tags

Assign Execute Permissions

chmod +x copy.sh

Run the copy job

./copy.sh

Note

You can replace europe-west2... with any Docker compliant repo. Only tested with GCR and GAR

footnotes

If you are not copying to GAR

You may want to look at the below

https://github.com/containers/skopeo

Want to make this site better? Open a PR or help fund hosting costs