Thursday, January 23, 2020

Pushing Local Docker Image to an Azure Container Registry

In this post, let's see how we can push a local docker image to an Azure Container Registry. For this post, I am using a very simple local docker image kube-weather:dev which I have created in my previous post: Deploying an ASP.NET Core Application On a Local Kubernetes Cluster.

First, let's create an Azure Container Registry (ACR). It's actually pretty straight forward, don't think any explanations are necessary.
Create an ACR
Then we need to push our image. For that, we will be using Azure CLI and make sure you have Azure CLI installed. 

Now then open up a PowerShell window and run the below command to login to Azure.
PS C:\Users\Jaliya> az login
It will open up a browser and upon sign in, it will list down all the subscriptions (with it's information such as id etc.) you have access to. If you have multiple, run the below command to find out what subscription is selected as default by Azure CLI.
PS C:\Users\Jaliya> az account show
If it's not the subscription where you have created the ACR in, you can change the subscription by running the below command.
PS C:\Users\Jaliya> az account set --subscription {id of the target subscription}
Once the correct subscription is selected, let's sign in to our ACR. For that, run the following command.
PS C:\Users\Jaliya> az acr login --name playground01
Login Succeeded
Here the name is whatever the name you have given for your ACR. In my case, it was playground01 and I am logged in.

Now run the below command to create a new image of kube-weather:dev image.
PS C:\Users\Jaliya> docker tag kube-weather:dev playground01.azurecr.io/kube-weather:dev
Here the target image should be in the following format : YourACRLoginServer:TargetImageName:Tag.
Login server
And now if you run docker images command, you will see a new image is created referencing the original image and have the same image id.
PS C:\Users\Jaliya> docker images
REPOSITORY                                        TAG                 IMAGE ID            CREATED             SIZE
kube-weather                                      dev                 d9cd7bec80e7        2 days ago          208MB
playground01.azurecr.io/kube-weather              dev                 d9cd7bec80e7        2 days ago          208MB
Now we are almost there. The final step is to push the new image to our ACR. For that, let's run the below command. And it will take some time based on the size and will display you a progressive output.
PS C:\Users\Jaliya> docker push playground01.azurecr.io/kube-weather:dev
The push refers to repository [playground01.azurecr.io/kube-weather]
5f3ec39d44c0: Pushed
b4ab3aec213b: Pushed
05682a6a4056: Pushed
fcd021389694: Pushed
2c52aed6692d: Pushed
c51868eee26f: Pushed
556c5fb0d91b: Pushed
dev: digest: sha256:b2725ccbc89e9684e406d5a20213562f9908e93f402570821a98285bc8d9a81d size: 1790
All good. Now if you have a look at our ACR, our kube-weather image should be there.
ACR-Repositories
And it is.

Hope this helps.

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment