Deploy Docker Containers to Azure App Services!

Mahedi Hasan Jisan
3 min readNov 17, 2021

This article would be pretty short because we will only focus on how to deploy docker images to Azure Container Registry resources and run it there.

If you have something on your own, that is completely okay. But if you want to check my example, then you can use the following GitHub repo:

Let’s look into the code and verify it in the local machine:

→ App.py:

from flask import Flask
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
app = Flask(__name__)@app.route('/<string:line>')
def main(line: str):
tokens = nltk.word_tokenize(line)
return {
'POS-Tagging': nltk.pos_tag(tokens)
}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)

It’s a simple flask app. We have used NLTK to word tokenize a sentence and return the results of poss-tagging.

→ Dockerfile:

# base image
FROM ubuntu:18.04
# setting the directory in the container
COPY . /usr/src/app
WORKDIR /usr/src/app
# Installing update and upgrade along with python
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
# Installing the other dependencies
RUN pip3 install -r requirements.txt
# Exposing the port
EXPOSE 80
# The startup command
CMD [ "python3", "/usr/src/app/app.py" ]

In this example, we have created our own image. We took ubuntu as our base image. Then, we installed everything that is needed to run our app: python, pip, requirements.txt! We exposed the app on port 80! And specified the startup command of the container.

→ Fire it up:

docker build -t jisan.azurecr.io/flask-docker-demo:latest
docker run -d -p 80:80 jisan.azurecr.io/flask-docker-demo:latest
localhost:80

→ Microsoft Azure:

Create an account: https://portal.azure.com/#home

  • Step 1: Create resource → containers → Create a new container registry! (Basic)
After initial setup!
  • Download the repository and create the image using docker-compose. To build the image, tag it with your azure login server name.

Example: “docker run -d -p 80:80 jisan.azurecr.io/flask-docker-demo:latest

  • Install Azure CLI

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

→ Check Version: az — version

  • Login to Azure Registry:
  • Push the image to the Azure container registry:
  • Find the image in the repositories section:
  • Registry admin enable:
  • Now, we are going to create a container instance: (specify the port you set in your application)
  • Let’s see it in the live view:
<IP>/<string>

Simple and Effective! That’s it for today! Cheers! 🙌

--

--