In Part 1, we looked at cloning a sample Docker Container based on Python Django. We tested this Container Image by running it to ensure it operates correctly. We then created a new GitHub Repository and pushed our Docker Container Source Code into your own GitHub Repository.
In this second part, 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.
Part 2
Creating our Azure Container Registry (ACR)
In the Azure Portal, under Create a Resource, create a Container Registry. We will call ours ElanACR. Specify a Resource Group, a Location, choose Admin User of Enable, and choose the SKU you want. For purposes of demonstration, the Basic SKU will suffice. Click Create.
We can now see our ElanACR ACR within the ACR Resource Group.
In Azure Cloud Shell, we need to get the credential for our ACR in order to push our container image into ACR. You will see the passwords (there are two of them) as well as the username at the bottom. Run the following command:
az acr credential show --name ElanACR
Pushing our Container Image into ACR
Now that we have our ACR and the password, let’s head back to our local terminal and login to our container registry. Run the following command:
docker login ElanACR.azurecr.io --username ElanACR
When running the above command, it will ask you for your password. Enter one of the two passwords that you retrieved in Azure Cloud Shell.
Once authenticated successfully, you will see the following:
Now we have to tag our image before pushing it into our ACR. As our image that we tested is called mydockerwebimage, we will tag this image with our ACR FQDN and the version as latest. This versioning is important. Azure Web App Continuous Deployment will only pull image updates for images that have the same name, are in the same registry, and have the same version, it is makes sense to use latest for the version used for Azure Web App Continuous Deployment.
Run the following command:
docker tag mydockerwebimage ElanACR.azurecr.io/mydockerwebimage:latest
After running the above command and then typing in docker images, we can now see our new image, ElanACR.azurecr.io/mydockerwebimage with the tag of latest.
Let’s push our new image up to ACR. Run the following command:
docker push ElanACR.azurecr.io/mydockerwebimage:latest
We will begin to see our image be pushed into ACR.
Once it is successfully pushed, you will see all container layers be marked as Pushed.
Creating Azure Web App for Containers
In the Azure Portal, under Create a Resource, create an Azure Web App. We will call ours ACRTasksBlog. Specify a Resource Group, a Location, and a Docker Container leveraging Linux For purposes of demonstration, for the App Service Plan, the Basic B1 SKU will suffice.
Click “Next: Docker”. Choose your Azure Container Registry for the Image Source. Ensure you specify the correct Registry, Image, and Tag. Click “Review + Create” and create your Azure Web App.
We now successfully have an Azure App Service (Azure Web App in this case) and an App Service Plan.
Within the App Service, click on Configuration, and Choose New application setting. We must add an application setting so Azure Web App knows that the Container Port is 8000.
Specify the name as WEBSITES_PORT and the Value of 8000. Click OK. Then click Save at the top of Application Settings.
If you click on Container Settings from within the Azure Web App, you can check the logs to see what the status is of the Azure Web App pulling the container. The first time you access the app, it may take some time because App Service needs to pull the entire image.
After a minute or so, we can see that the image was downloaded and is being extracted. Patience!
You can keep trying to refresh the browser and refreshing the logs to check the status. Your URL will be https://[NameofWebApp].azurewebsites.net. In our case, since we created the Web App with the name of acrtasksblog, our URL will be https://acrtasksblog.azurewebsites.net.
Let’s try the URL in our browser. BOOM! We have a successful Azure Web App webpage using a container.
In Part 3, we 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.
Leave a Reply