Continuous deployment with Web App for Containers using Azure Container Registry

Continuous deployment with Web App for Containers

In this article we will see how can create a Azure Web app for container (on Linux) and setup an docker / custom image on it.

Once that it done we shall automate the deployment which will be triggered and deployed to our web app as soon as we push the container image to our Azure Container Registry

Steps summary:

Setting up Docker :

  1. Download docker CLI or docker for windows.
  2. Signup for a docker account.
  3. Login to docker / CLI on your PC.
  4. Download any container image from Docker hub to local using CLI.
  5. Tag the image.
  6. Verify image is up and running on local.

Setting up Azure Container Registry:

  1. Create an Azure Container Registry.
  2. Login to Azure Container Registry from docker.
  3. Map the Tagged container image with Azure Container Registry account with a repository name and tags.
  4. Push the local docker image to Azure Container

Setting up Azure Web app for container for that Image:

  1. Create Web app for container.
  2. In Docker Container option, select the Azure Container registry.
  3. Select the values for Registry, Image, Tag & hit Save.
  4. Restart the Web App.
  5. Browser the web app to see if the image is up and running on Web app.

Setting up Continuous Deployment for Azure Web app for container for that Image:

  1. Enable the auto deployment mode on Web app.
  2. Get the service URL from publishing profile.
  3. Go to Azure Container Registry & create Web hook.
  4. Fill up the values and save and do a test ping.

Verifying Continuous Deployment:

  1. Go to Docker CLI.
  2. Modify the image or give the same tag mapping to any other image.
  3. Push the image to Azure Container
  4. Restart the Web app.
  5. Browse the web app to see that new image is up and running.
  6. After some time, the auto deployment logs are visible in the Azure Container Registryà Web hook à Logs/events

 

So, if you haven’t sleep so far, let’s see it in action.

 

 

  1. Download docker CLI or docker for windows.

I am installing docker on my local windows 10 from https://www.docker.com/docker-windows

after installation I could see this in tray icon:

  1. Signup for a docker account at https://cloud.docker.com/ & activate the account & sign in .
  2. Login to docker on your PC.

 

  1. Download any container image from Docker hub to local using CLI :

For this example, I am using nginx image , thus we shall download it from docker by running this command on command prompt.

 

docker pull nginx

  1. By default, the image tag is taken as latest.
  2. Verify image is up and running on local :

running this command on command prompt

 

docker run -it --rm -p 8080:80 nginx

and in browser open url  http://localhost:8080/

 

  1. Create an Azure Container Registry:

Refer here : https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal

 

Login to azure portal and create a Azure Container Registry over there from market place & get the ID and password for Azure Container Registry  as per documentation link above.

 

Please enable the Admin User option .

Please note that Login Server name  , which is  <registoryname>. azurecr.io

 

From here onward for example purpose we shall user the registoryname as myregistry considering you have created the registry using this name.

 

Also note the Username and password.

 

 

  1. Login to Azure Container Registry from docker.

Run this command on CLI

docker login myregistry.azurecr.io -u xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -p <password>

 

Now my CLI / Local docker si connected with Azure Container Registry.

  1. Map the Tagged container image with Azure Container Registry account with a repository name and tags.

docker tag nginx myregistry.azurecr.io/samples1/php

by using above command , I am instructing that my local image named nginx should be mapped with my azure container registry end point myregistry.azurecr.io/samples1/php  which is actually creating a repository Image with name samples1/php  .

we will see this repository in Azure Portal, once we push the image in next step.

Please note : don’t get confused with tag here , the tag in step 5 is the tag for image and we can have multiple tags and default tag is “latest”.

 

But Tag command here is kind of mapper between your image and registry end point.

 

  1. Push the local docker image to Azure Container

 

docker push myregistry.azurecr.io/samples1/php

issuing this command , will push my image which I have already tagged/mapped  in  step 9 and this will create a repository on azure container registry.

 

  1. Create Web app for container.

From Azure market place, create a new web app for containers & select the containers values here (which covers up the steps 12 & 13 as well)

After create button click it will create that web app in few minutes from that image which we pushed earlier.

 

 

 

 

  1. In Docker Container option, select the Azure Container registry.

Same was already done in step 11, however can be reconfigure at Web app’s “Docker Container” option

  1. Select the values for Registry, Image, Tag & hit Save.

Same was already done in step 11 , however can be reconfigure at Web app’s “Docker Container” option

 

  1. Restart the Web App.

If you are changing the Registry, Image, Tag , please restart the web app after save to reflect the changes.

 

  1. Browser the web app to see if the image is up and running on Web app.

Now browsing my web app will show the container image.

 

  1. Enable the auto deployment mode on Web app.

In the App settings, add an app setting called DOCKER_ENABLE_CI with the value true.

 

  1. Get the service URL from publishing profile.

For the Webhook URL, you need to have the following endpoint: https://<publishingusername>:<publishingpwd>@<sitename>.scm.azurewebsites.net/docker/hook.

You can obtain your publishingusername and publishingpwd by downloading the web app publish profile using the Azure portal.

So service url looks like :

https://<publishingusername>:<publishingpwd>@<sitename>.scm.azurewebsites.net/docker/hook.

  1. Go to Azure Container Registry & create Web hook.

Couple of values which you will require are :

Webhookname : any meaning full name

Service URI : the service uri from step number 17 something like below :

 

https://<publishingusername>:<publishingpwd>@<sitename>.scm.azurewebsites.net/docker/hook

 

Scope : this will be in format of Image:Tag  (see point number 5,9 & 11)

Thus earlier we have been using Image as samples1/php  and by default the tag was latest ,

Thus the value here will be samples1/php :latest

I have created one more image names samples1/php with tag latest and that what is being shown here in figure.

  1. Fill up the values and save and do a test ping.

 

Sometime your kudu is down or process not running ,thus you may encounter error , please make sure your KUDU process is running while ping or deployment .

Now your continuous deployment is up and running, you can test it with deploying modified image or new image with same tag , lets see how to do it ?

 

Here to test it either we can :

  • Modify the locally residing nginx image
  • rebuild it so that changes are persistence
  • push the new image on Azure portal to verify it should auto deploy .

OR

  • Or we can do a trick by using another container image lets say phpmyadmin docker image.
  • tag it with same name/endpoint as nginx end point .
  • deploy that image to azure web app
  • so now our Azure Web app will show phpmyadmin page on browsing which is also a verification that auto deployment worked.

I am going to show second way by putting phpmyadmin image via continuous deployment.

 

  1. Go to Docker CLI.
  2. Modify the image or give the same tag mapping to any other image.
  • So now to do so , I will download the phpmyadmin container image from docker by running following command :

docker pull phpmyadmin/phpmyadmin

  • Now if I verify the images in my docker by running command

docker images

it shows something like :

 

 

 

watch carefully here:

Line 2 : the image NGINX is having tag as latest with image id 40960******

as I have mapped that image with Azure container registry end point sample1/php,

Line 1 : my sample1/php end point is having same tag and same image id as line 2.

 

This also gives us indication , that currently which image is mapped to our azure registry end point.

  • Line number 7 : Now my recently downloaded phpmyadmin/phpmyadmin image tag is also latest ,with image id  f4674******

But that is not mapped with my existing azure end point ,

Thus in line number 9  , that end point with that image id is having Tag as <none>.

  • Now let me map the phpmyadmin image to azure end point by running following command :

docker tag phpmyadmin/phpmyadmin  myregistry.azurecr.io/samples1/php

  • Now verify the docker image again to see if it pointing to correct end point

  • Look closely ,
  • Now line 1 NGINX local image having image id 4096*** with tag latest.
  • Line number 4 :This same image id 4096*** , the tag has become <none> , that means now NGINX is not pointing to azure end point samples1/php any more
  • Line number 5 : Phpmyadmin/phpmyadmin local one having image id f46764*** with tag latest ,
  • Line number 6 : Same image id is now pointing to azure container registry end point samples1/php with tag latest.
  • From above, we have mapped phpmyadmin/phpmyadmin image to azure container registry and pushing this on on registry will auto deploye phpmyadmin image on our web app , which is currently running nginx image.

 

  1. Push the image to Azure Container

 

docker push myregistry.azurecr.io/samples1/php

Run following command will push this image on azure registory , which should ideally push it on Azure web app as well .

 

 

Now , in few minutes it should auto deploy phpmyadmin container on my web app o

  1. Browse the web app to see that new image is up and running.

  1. After some time, the auto deployment logs are visible in the Azure Container Registryà Web hook à Logs/events

 

In My next post I will share some basic troubleshooting for auto deployment failures.

Like This (2)
Dislike This (0)

Leave a Reply

Your email address will not be published. Required fields are marked *