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 :

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:

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: [].

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 
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": {
    "": "gcloud", 
    "": "gcloud", 
    "": "gcloud", 
    "": "gcloud", 
    "": "gcloud", 
    "": "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
$ sudo docker push

That’s it!

Run containerized python app in kubernetes

Run containerized python app in kubernetes

First of all we need a Docker image that will be run inside the kubernetes cluster. So I assumed that we already have a kubernetes cluster. So the next we do is to build the docker image or you can use your docker image yourself.

But in this tutorial, I will show you how to run the containerized python app with my version from the start.

What we need

These applications should be installed on your local machine before get started. In my case, I use my remote server with ubuntu 16.04 installed.

1. Docker
2. Kubernetes

Setup Kubernetes on Ubuntu 16.04

Build docker image

Let’s begin with clone of of my repo that contains Dockerfile to build the image:

$ git clone
$ cd docker-images/simple-python-app/
~/docker-images/simple-python-app$ sudo docker build -t simple .

Wait until the process successfully built. And then you’ll see a new docker image when you type this command:

$ docker images

Push docker image to repository (docker hub)

Before pushing the image to docker hub, we need to tag the successfully built image.

$ docker tag fbd064597ae4 cerpin/simple:1.0

Push the image

$ docker push cerpin/simple
The push refers to a repository []
bc69ee44ef1a: Pushed 
7957c9ab59bb: Pushed 
2366fc011ccb: Pushed 
b18f9eea2de6: Pushed 
6213b3fcd974: Pushed 
fa767832af66: Pushed 
bcff331e13e3: Mounted from cerpin/test 
2166dba7c95b: Mounted from cerpin/test 
5e95929b2798: Mounted from cerpin/test 
c2af38e6b250: Mounted from cerpin/test 
0a42ee6ceccb: Mounted from cerpin/test

After it pushed. You will have the docker image in the repository and ready to use it:


Run the image in kubernetes

First of all, I’m not a big fan of kubectl command, so I usually make a symlink to create the shorter version of kubectl:

$ sudo ln -s /usr/bin/kubectl /usr/bin/cap

Run the docker image in kubernetes

$ cap run simple --image=cerpin/simple:1.0

Then the container will be created. Just wait a moment until the state becomes Running

$ cap get pods
simple-79d85db8b9-466kd 1/1 Running 0 26m

After it’s ready, expose the service with port 5002 to become LoadBalancer. So the service will be accessible from the outside world

$ cap expose deployment simple --type=LoadBalancer --port=5002

Check the service that has been exposed:

$ cap get services
simple LoadBalancer <pending> 5002:31969/TCP 21m

You will see that the service will have forwarded port to 31969 from 5002.

If you open up the browser and navigate to http://external IP:31969, you’ll see the app is running.

Or, just use a curl command instead:

$ curl
"message": "welcome", 
"status": "ok"

Setup Kubernetes on Ubuntu 16.04


This setup is supposedly to install the kubernetes on ubuntu machine with version 16.04 (64bit). I did this in the cloud and have worked perfectly.

# whoami && pwd
# apt-get update
# apt-get install -y apt-transport-https
# curl -s | sudo apt-key add -
# echo "deb kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
# apt-get update -y
# apt install
# apt-get install -y kubelet kubeadm kubernetes-cni

Check the swaps, if there any, swith them off

# /proc/swaps

Init kubernetes for the first time using kubeadm:

# kubeadm init --pod-network-cidr= --apiserver-advertise-address=<private IP>

*Note: Change <private IP> to <public IP>, if you run the kubernetes master on single node and wish to publicly open.

# cp /etc/kubernetes/admin.conf $HOME/
# export KUBECONFIG=$HOME/admin.conf
# echo "export KUBECONFIG=$HOME/admin.conf" | tee -a ~/.bashrc

Check pods status, wait until all running

# kubectl get pods --all-namespaces

When their status are RUNNING, moving forward install the network/flannel. Please choose between these two below, I prefer to use the calico one (the second).

# kubectl apply -f
# kubectl apply -f

# or

# kubectl apply -f

Continue to taint the nodes:

# kubectl taint nodes --all

Install kubernetes dashboard

# kubectl apply -f

Create user dashboard


apiVersion: v1
kind: ServiceAccount
  name: admin-user
  namespace: kube-system


kind: ClusterRoleBinding
  name: admin-user
  kind: ClusterRole
  name: cluster-admin
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system
# kubectl create -f create-user.yml
# kubectl create -f create-role.yml
# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

How to set the kubernetes dashboard to publicly accessible with public IP

Read this :—1.7.X-and-above


Create docker image and push to AWS ECR

Image tag : test-image

awsudo -u aws-profile aws ecr get-login --no-include-email --region ap-southeast-1
sudo docker build -t test-image .
sudo docker tag codebuild:test-image
sudo docker push


Fix cannot access internet in your docker container

I use docker for testing environment. Somehow I found out that the docker container cannot access the internet and the solution is really simple:

$ sudo ifconfig docker0 down
$ sudo service docker restart
$ sudo ifconfig docker0 up


$ sudo vim /etc/default/docker
DOCKER_OPTS="--dns --dns --dns"

Which: in my localhost/laptop

Kubernetes cheatsheet

To list all deployments:

kubectl get deployments --all-namespaces

To delete deployment:

kubectl delete -n NAMESPACE deployment DEPLOYMENT

To get admin user token dashboard

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

Allow master to run pod

kubectl taint nodes --all

To join master node

kubeadm join --token <some-token> <host-master>:6443 --discovery-token-ca-cert-hash sha256:<some-sha256-hash>




Docker command cheatsheet

docker build image

$ sudo docker build -t image-name .

docker to start a container from image

$ sudo docker run -itd --name jenkins --publish 8080:8080 --publish 50000:50000 jenkins

docker to get inside the container

$ sudo docker exec -it jenkins bash

docker stop container

$ sudo docker stop image-id/name

docker remove container

$ sudo docker rm image-id/name

docker remove containers based on specific image name/tag

sudo docker ps -a | awk '{ print $1,$2 }' | grep centos:7 | awk '{print $1 }' | xargs -I {} sudo docker rm {}

docker remove image

$ sudo docker rmi image-id

docker remove images with no tag

$ sudo docker rmi $(sudo docker images --filter "dangling=true" -q --no-trunc)