• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Disclaimer & Policy

Elan Shudnow's Blog

MVP Logo
  • Azure
  • Exchange
  • Lync

ACR Tasks to Automatically Update Azure Web App Containers – Part 1

December 7, 2019 by Elan Shudnow Leave a Comment

One of the features Azure Web App provides is to leverage containers for the website you are hosting. The offering is officially called, “Web App for Containers.” This provides several benefits:

  • Easily deploy and run containers applications that scale with your business
  • Use a fully-managed platform to perform infrastructure maintenance
  • Take advantage of build-in auto scaling and load balancing
  • Streamline CI/CD with Docker Hub, Azure Container Registry (ACR), and GitHub

ACR is an Azure Resource in which you can store containers. One of the features of ACR is Tasks. Tasks allow you to automate container building in the following scenarios:

  • Detect source code changes in GitHub or Azure DevOps and automatically build a new image and store in ACR
  • Detect base image update and automatically build a new image and store in ACR
  • On a schedule, build a new image and store in ACR
  • Manually build and push a single container image on-demand into ACR without needing a local Docker Engine installation. Think docker build & docker push in the cloud.
  • Multi-step task to extend the single image build-and-push capability of ACR Tasks with multi-step, multi-container-based workflows.

We will be leveraging the first method in which we will build a container, modify the source code from within GitHub, and automatically trigger an image build in ACR, and have Azure Web App Continuous Deployment update the container image used.

This is a three part article series.

In this first part, we look at cloning a sample Docker Container based on Python Django. We test this Container Image by running it to ensure it operates correctly. We then create a new GitHub Repository and push our Docker Container Source Code into your own GitHub Repository.

In the second part, we will take a look at creating an ACR, pushing our image up to ACR, and setting up Azure Web App to use our container image and test the website for production readability.

In the third part, we will take a look at making an update to our container image in a way as to not affect our original image, we test our new container image, we set up our ACR Task with a trigger for Source Code, we set up our Azure Web App for Continuous Deployment, push our updated source code to GitHub, validate our ACR Task detected the change, validate ACR builds the new image, validate Azure Web App pulls the updated image, and finally validate our Azure Web App website is reflecting the new production change.

Part 1

Part 2

Part 3

Clone a Sample Repository and Test Docker Image

Let’s clone a sample repository to your local machine using the following command:

git clone https://github.com/Azure-Samples/docker-django-webapp-linux.git --config core.autocrlf=input

Let’s build the docker image and test it before we push this code up to GitHub. This will require you to have Docker installed. For Windows/Mac Users, install Docker Desktop which you can download here.

You can see currently, there are no local docker containers or images.

Start by executing the following docker command from within the docker-django-webapp-linux directory:

docker build --tag mydockerwebimage .

The docker image is now built.

We can see our mydockerwebimage image has successfully been created. The reason we also see the python image is because in our dockerfile, we are building our image from the base python image. So in order to create our image from the python base image, the python base image is also downloaded.

Now let’s run our mydockerwebimage image to ensure that it runs successfully before we push the source code out to GitHub and set up our Azure Web App for containers.

We do this by running the following command:

docker run -p 8000:8000 mydockerwebimage

If we launch a browser and go to https://127.0.0.1:8000, we can see our website as well as the streaming log in the Command Prompt.

The reason we are going to port 8000, is that our DockerFile exposes port 8000. When we execute docker run with -p 8000:8000, the first port is the host port and the second port is the container port. It is important to ensure the 2nd port, the container port, matches one of the ports defined under EXPOSE within your dockerfile.

Push our Source Code into a GitHub Repository

In GitHub, create a new Repository. I called mine, ACRTasksBlog.

I also created a new directory on my local file system called ACRTasksBlog and copied all the source code to it.

To associate this directory with the new GitHub Repository, I run the following:

echo "# ACRTasksBlog" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/ElanShudnow/ACRTasksBlog.git
git push -u origin master

Then to add all the source code into GitHub, run the following commands:

git add .
git commit -m "Adding docker source code"
git push

We can now successfully see all our code in our GitHub Repository.

In Part 2, we take a look at creating an ACR, pushing our image up to ACR, and setting up Azure Web App to use our container image and test the website for production readability.

Share this:

  • Twitter
  • LinkedIn
  • Reddit

Filed Under: Azure Tagged With: ACR, Azure, Azure Web App, Docker

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • YouTube

More to See

Azure Runbooks Connecting to Exchange Online and Microsoft Graph

July 22, 2022 By Elan Shudnow

Using Python 3.8.0 Azure Runbooks with Python Packages

July 11, 2022 By Elan Shudnow

Preserving UNC Path after Azure Files Migration using DFS-N

April 10, 2022 By Elan Shudnow

Pin Azure VM Availability Sets into an Availability Zone

April 9, 2022 By Elan Shudnow

Tags

ACR Always Encrypted Ansible Automation Availability Sets Availability Zones Azure Azure Active Directory Azure Application Gateway Azure Files Azure Firewall Azure Key Vault Azure Load Balancer Azure Migrate Azure Monitor Azure Web App Backup Exec CDN Cluster DevOps DFS Docker DPM Event Grid Exchange Exchange 2010 Function App ISA iSCSI Log Analytics Logic App Lync Microsoft Graph OCS Office Personal PowerShell Proximity Placement Groups Runbook SCOM SQL Storage Accounts Virtual Machines Windows Server 2008 Windows Server 2008 R2

Footer

About Me

Microsoft Cloud Solution Architect focused on Azure IaaS, PaaS, DevOps, Ansible, Terraform, ARM and PowerShell.

Previously a 6x Microsoft MVP in Exchange Server and Lync Server.

My hobbies include watching sports (Baseball, Football and Hockey) as well as Aviation.

Recent

  • Pre-creating Azure AD App for Azure Migrate
  • Azure Runbooks Connecting to Exchange Online and Microsoft Graph
  • Using Python 3.8.0 Azure Runbooks with Python Packages
  • Preserving UNC Path after Azure Files Migration using DFS-N
  • Pin Azure VM Availability Sets into an Availability Zone

Search

Tags

ACR Always Encrypted Ansible Automation Availability Sets Availability Zones Azure Azure Active Directory Azure Application Gateway Azure Files Azure Firewall Azure Key Vault Azure Load Balancer Azure Migrate Azure Monitor Azure Web App Backup Exec CDN Cluster DevOps DFS Docker DPM Event Grid Exchange Exchange 2010 Function App ISA iSCSI Log Analytics Logic App Lync Microsoft Graph OCS Office Personal PowerShell Proximity Placement Groups Runbook SCOM SQL Storage Accounts Virtual Machines Windows Server 2008 Windows Server 2008 R2

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in