How to Push Docker Image to Google Cloud Repository (GCR) (Easy steps!)

 

 

 

Here’s how to push your local docker image to your GCR (Google Cloud Repository). You might want to use your own docker image later for your containerized app or kubernetes.

For this research, I use Ubuntu 18.04.03 LTS

Install gcloud, see the full instructions here : https://cloud.google.com/sdk/docs/quickstarts

Once you’ve installed the gcloud, let’s continue to the next step:

$ gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.                                                                                                                                                                                               
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)?  y

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?code_challenge=00SNwoATS92Is6deNqmONmgLM_RPM8x7n_IT_9ZU55s&prompt=select_account&code_challenge_method=S256&access_type=offline&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=xxxxxxxxxxxxxxxxxxxxxxx


Enter verification code: 

For the first time initiation, gcloud will ask you to log in. Therefore it will provide the link that you can click on your browser. Follow the instruction from google browser, then you will get the verification code. You also will be asked to pick the cloud project that you want to use:

Enter verification code: 4/sgEzW-mHbbknYMPEIM7vPPjENJuIxRnT1ov9xxxxxxxxxx
You are logged in as: [xxxxxx@gmail.com].

Pick cloud project to use: 
 [1] my-project-id
 [2] Create a new project
Please enter numeric choice or text value (must exactly match list 
item):  1

Next, select the the region and zone:

Your current project has been set to: [my-project-id].

Do you want to configure a default Compute Region and Zone? (Y/n)?  Y

Which Google Compute Engine zone would you like to use as project 
default?
If you do not specify a zone via a command line flag while working 
with Compute Engine resources, the default is assumed.
 [1] us-east1-b
 [2] us-east1-c
 [3] us-east1-d
 [4] us-east4-c
 [5] us-east4-b
 [6] us-east4-a
 [7] us-central1-c
 [8] us-central1-a
 [9] us-central1-f
 [10] us-central1-b
 [11] us-west1-b
 [12] us-west1-c
 [13] us-west1-a
 [14] europe-west4-a
 [15] europe-west4-b
 [16] europe-west4-c
 [17] europe-west1-b
 [18] europe-west1-d
 [19] europe-west1-c
 [20] europe-west3-c
 [21] europe-west3-a
 [22] europe-west3-b
 [23] europe-west2-c
 [24] europe-west2-b
 [25] europe-west2-a
 [26] asia-east1-b
 [27] asia-east1-a
 [28] asia-east1-c
 [29] asia-southeast1-b
 [30] asia-southeast1-a
 [31] asia-southeast1-c
 [32] asia-northeast1-b
 [33] asia-northeast1-c
 [34] asia-northeast1-a
 [35] asia-south1-c
 [36] asia-south1-b
 [37] asia-south1-a
 [38] australia-southeast1-b
 [39] australia-southeast1-c
 [40] australia-southeast1-a
 [41] southamerica-east1-b
 [42] southamerica-east1-c
 [43] southamerica-east1-a
 [44] asia-east2-a
 [45] asia-east2-b
 [46] asia-east2-c
 [47] asia-northeast2-a
 [48] asia-northeast2-b
 [49] asia-northeast2-c
 [50] europe-north1-a
Did not print [12] options.
Too many options [62]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list 
item):  30

Next, we need to configure the docker config. Run the command below to add some config file. Input Y if prompted.

$ gcloud auth configure-docker
The following settings will be added to your Docker config file 
located at [/home/ubuntu/.docker/config.json]:
 {
  "credHelpers": {
    "gcr.io": "gcloud", 
    "us.gcr.io": "gcloud", 
    "eu.gcr.io": "gcloud", 
    "asia.gcr.io": "gcloud", 
    "staging-k8s.gcr.io": "gcloud", 
    "marketplace.gcr.io": "gcloud"
  }
}

Do you want to continue (Y/n)?  Y

Docker configuration file updated.

Now, let’s build your docker image, tag, and push it to your GCR registry

$ sudo docker build -t simple-image:v1 .
$ sudo docker tag simple-image:v1 asia.gcr.io/my-project-id/simple-image:v1
$ sudo docker push asia.gcr.io/my-project-id/simple-image:v1

That’s it!

Leave a Comment