The JS and Python bots deployed in Azure for the functional tests are deployed in Docker containers by creating an Azure container registry. This guide will show you how to create a custom container with a Linux/Python image and a bot sample, how to use it locally with BotFramework-Emulator, deploy it to a container's registry and create a Web App from the custom container.
For additional information visit the official Docker's website.
- Docker Desktop
- BotFramework-Emulator
- Ngrok
- Active Azure Subscription
- Bot Resources
- Azure App Service Plan (guide)
- Bot Channel Registration (guide)
- App Registration (guide) (MicrosoftAppId and Microsoft AppPassword variables)
- Image: python:3.8-buster (Dockerfile, Packages)
- System: Linux
-
Install docker (if you don't have it already). A restart might be required.
-
Use a bot sample (eg. SimpleHostBotPython). Clone the repository and move to the sample folder of the bot of your choice.
Note: when using aiohttp to host the app, ensure the host property is empty when the run_app method is executed so the library starts broadcasting (0.0.0.0). This can be done by modifyin app.py in the source.
from aiohttp import web web.run_app(web.Application(), host="localhost", port=37000)
-
Create a file named DockerFile (without extension) inside the bot's folder. Add the following lines in the file.
# Specify the base image to use FROM python:3.8-buster # Specify the working directory where the bot is located. This will be the default location for all subsequent commands. WORKDIR /app # Take all the files located in the current directory and copy them into the image. COPY . . # Install bot's dependencies RUN pip3 install -r requirements.txt # Execute the bot CMD python app.py
-
Execute the build command in the console to build the container.
docker build --tag <Name and optionally a tag in the 'name:tag' format> .
eg.
docker build --tag simplehostbotpython .
-
Execute the run command in the console to start the container
docker run --publish <Publish a container's port(s) to the host> <Image name assigned in the tag>
eg.
docker run --publish 37000:37000 simplehostbotpython
If you are presented with the following error, please refer to the step 2.
OSError: [Errno 99] error while attempting to bind on address ('::1', 37000, 0, 0): cannot assign requested address
-
When using BotFramework-Emulator, ensure the "Bypass ngrok from local addresses" option is disabled.
-
Create an Azure container registry.
Once the resource is created, head over to the Access Keys section and enable Admin user. This will allow us to login remotely to the registry and push our container.
Take note of the Login server, Username, and password values, we will need them later.
-
Login into the Azure container registry by executing the login command in a console.
az acr login --name <Name of the Container Registry>
eg.
az acr login --name bffncontainerregistry
If you are presented with the following error.
run
az login
-
Execute the tag command in the console to tag the container.
docker tag <Image name assigned in the tag> <Container Registry Login server>/<Name and optionally a tag in the 'name:tag' format. Tag defaults to 'latest'>
eg.
docker tag simplehostbotpython bffncontainerregistry.azurecr.io/simplehostbotpython:v1
-
Execute the push command in the console to push the container to the registry.
docker push <Tag created in the previous step>
eg.
push bffncontainerregistry.azurecr.io/simplehostbotpython:v1
If the error
unauthorized: authentication required
shows up, you are either, not logged in, or you used a mix of upper and lower case letters in the console commands. Please repeat tagging and pushing the container using all lowercase letters for the registry names.Your container is now deployed, you can check the uploaded containers in the container registry under the Repositories section.
-
Create a WebApp.
-
Access the WebApp configuration and assign the WEBSITES_PORT variable with the port to use to communicate with the container. Add the MicrosoftAppId and MicrosoftAppPassword obtained from the created AppRegistration.
-
Add the WebApp URL in the Bot Channel Registration messaging endpoint. You can obtain the URL from WebApp's summary.
-
The bot is ready. You can access the Bot Channel Registration and start chatting with the bot.