Skip to content

Adding Container Images to Google Container Registry (GCR)

Avatar photo

https://www.linkedin.com/in/gineesh/ https://twitter.com/GiniGangadharan

Image : cloud.google.com

Google Container Registry (GCR) is a service in Google Cloud Platform (GCP) to manage your own docker container repository. This is fully managed service and you can store your custom container images as well as common images from other image repositories. Also, you can implement fine-grained access control on your private container registry using GCR.

See quick demo here

Let’s see how we can add an image to our own GCR and see details in Web GUI.

If you open Container Registry for first time, you will see a blank list as above as you haven’t setup anything inside. Let’s pull some image from docker hub (hub.docker.com) and store it in our private GCR. For testing I am pulling some sample images like gogs. (Gogs is simple self-hosted Git service with Web GUI; Learn more)

devops@cloudshell:~$ gcloud auth configure-docker
gcloud credential helpers already registered correctly.

You can do this via Google Cloud Shell or setup your workstation with Cloud SDK (Make sure you have configured credentials and enabled billing for the project). For an easy demo, I am using Cloud Shell from GCP Console.

Pull Docker Container Image

Let’s see what we have on the cloud shell (or your workstation now.

devops@cloudshell:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
devops@cloudshell:~$

Now we will pull gogs image from docker hub.

devops@cloudshell:~$ docker pull gogs/gogs
Using default tag: latest
latest: Pulling from gogs/gogs
9d48c3bd43c5: Pull complete
1013a6a6073e: Pull complete
f074cb3ecafc: Pull complete
33433d770f0d: Pull complete
b464f169dfd9: Pull complete
77e3c5692f7d: Pull complete
e6d8ab097b45: Pull complete
13266a8e4353: Pull complete
2ac951b0051b: Pull complete
266414b76811: Pull complete
Digest: sha256:48cd3d14f6d5c9f73cd462b42e67f7a021b299da8fdaa2003cc164fe6ed08a38
Status: Downloaded newer image for gogs/gogs:latest
docker.io/gogs/gogs:latest

And see what all images we have now locally.

devops@cloudshell:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
gogs/gogs           latest              9dee4424cf01        2 weeks ago         99.8MB

Tag Images with registry name

Now we need to follow the normal docker image manipulation process like tagging image with new registry name and push it to our registry.

devops@cloudshell:~$ docker tag gogs/gogs gcr.io/devops-vinmel/gogs:latest

gogs/gogs is our local image which we pulled from docker hub. And, gcr.io/devops-vinmel/gogs:latest is the new image tag where,

  • gcr.io is the google container registry (it can be us.gcr.io, eu.gcr.io etc, depends on the region/location)
  • devops-vinmel is my project I want to tag under.
  • gogs is my image name (You can use any name as well)
  • latest is the tag (you can use as 1.0, 2.1 etc)

Remember, there was only one entry earlier and now see how many image entries we have locally.

devops@cloudshell:~$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
gogs/gogs                   latest              9dee4424cf01        2 weeks ago         99.8MB
gcr.io/devops-vinmel/gogs   latest              9dee4424cf01        2 weeks ago         99.8MB

So, you have a new entry with your own tag (but pointing to same image ID).

Pushing Image to Registry

Let’s push our newly tagged image to registry, which we have tagged as gcr.io/devops-vinmel/gogs:latest

devops@cloudshell:~$ docker push gcr.io/devops-vinmel/gogs:latest
The push refers to repository [gcr.io/devops-vinmel/gogs]
472aa1d10b15: Pushed
1a0a9e02ec1d: Pushed
cda4f57c1811: Pushed
074fc7d49e95: Pushed
0f12e9fa2e77: Pushed
b8d11cf1485c: Pushed
e18f9d09a6f5: Pushed
b2f817b146eb: Pushed
acf16385892f: Pushed
03901b4a2ea8: Layer already exists
latest: digest: sha256:48cd3d14f6d5c9f73cd462b42e67f7a021b299da8fdaa2003cc164fe6ed08a38 size: 2415

Please note, when you push your new docker image to a registry with a new hostname (gcr.io or us.gcr.io), Google Container Registry will creates a storage bucket for storing this image.

That’s all, you have added a new container image in your own GCR and let’s see this on container registry GCP web console or via gcloud command.

devops@cloudshell:~ (devops-vinmel)$ gcloud container images list-tags gcr.io/devops-vinmel/gogs
DIGEST        TAGS    TIMESTAMP
48cd3d14f6d5  latest  2019-10-04T11:59:14

Yes, there is an entry with gogs and you can see content inside.

You can also see the pull command to use this image.

docker pull gcr.io/devops-vinmel/gogs:latest

Clean up

Once you tested or maybe if you want to remove images, you can simply do it from your GUI itself.

See Demo

Watch it on our YouTube Channel.

Disclaimer:

The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.

Avatar photo


https://www.linkedin.com/in/gineesh/ https://twitter.com/GiniGangadharan
Gineesh Madapparambath is the founder of techbeatly and he is the co-author of The Kubernetes Bible, Second Edition. and the author of 𝗔𝗻𝘀𝗶𝗯𝗹𝗲 𝗳𝗼𝗿 𝗥𝗲𝗮𝗹-𝗟𝗶𝗳𝗲 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻. He has worked as a Systems Engineer, Automation Specialist, and content author. His primary focus is on Ansible Automation, Containerisation (OpenShift & Kubernetes), and Infrastructure as Code (Terraform). (aka Gini Gangadharan - iamgini.com)

Comments

2 Responses

  1. […] Also read : How to add Container Images to Google Container Registry (GCR) […]

  2. Terri says:

    This article helped so much! Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.