How to Push Docker Images to GCR & Pull the same from GCR (Google Container Registry)
We have various options available to Store/Manage our Container Images.
- Docker Hub
- GCR (Google Container Registry)
- Amazon Elastic Container Registry (ECR)
All three have their own Pros and Cons.
Here we will deal with GCR (Google Container Registry) and we will see How we can push images to GCR and How we can pull images from GCR
Pre-requisites 1) Install Docker 2) Install Google Cloud SDK
Let's suppose we have some images available in our local computer. We can see using docker images command
We could see we have image 'node-app' available with tag 0.1
To push images to your private registry hosted by gcr, you need to tag the images with a registry name. The format is [hostname]/[project-id]/[image]:[tag].
For gcr: [hostname]= gcr.io
[project-id]= your project's ID
[image]= your image name
[tag]= any string tag of your choice. If unspecified, it defaults to "latest".
Now, we see 2 images one is node-app:0.1 and other starting with gcr.io/project_name/node-app:0.1
- Now time to push the Images to GCR, but before that we need to login to gcloud
gcloud auth login your_username
- Then we need to set the Project.
gcloud config set project your_project_id
- Once all done,we are set to push the image to GCR.
Verify in GCR
- Open http://cloud.google.com/ and login with your account.
- Go to Navigation menu ==> Container Registry ==> Images.
- Click on it, we will see the image which we have pushed
- To pull the stored image from GCR, use below command
Resources: googlecourses.qwiklabs.com - GSP055