Adding Container Images to Google Container Registry (GCR)

Gini Gangadharan

Gineesh Madapparambath | Backpacker, Foodie, Techie |
techbeatly.com | rovervibes.com
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.

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)

[email protected]:~$ 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.

[email protected]:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[email protected]:~$

Now we will pull gogs image from docker hub.

[email protected]:~$ 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.

[email protected]:~$ 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.

[email protected]:~$ 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.

[email protected]:~$ 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

devop[email protected]:~$ 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.

[email protected]:~ (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.

Gini Gangadharan

Gineesh Madapparambath | Backpacker, Foodie, Techie | techbeatly.com | rovervibes.com

You may also like...

Leave a Reply

avatar

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

  Subscribe  
Notify of
%d bloggers like this: