Posts Deploy a Docker Container to Azure Functions using an Azure DevOps YAML Pipeline
Deploy a Docker Container to Azure Functions using an Azure DevOps YAML Pipeline
Cancel

Deploy a Docker Container to Azure Functions using an Azure DevOps YAML Pipeline

In my last post, I created a YAML pipeline to build and deploy an Azure Function to Azure. Today, I will build the same Azure Function inside a Docker container and deploy the container to Azure.

Add Docker to the Azure Function

You can find the code of the demo on Github.

To add Docker to the Azure Function, right-click the project in Visual Studio and click Add –> Docker Support. Visual Studio automatically creates the Dockerfile for you.

If you want to learn more about adding Docker to a .NET 5 project, see my post Dockerize an ASP .NET Core Microservice and RabbitMQ.

Build a Docker Container inside a YAML Pipeline in Azure DevOps

In Azure DevOps, create a new pipeline (or edit the one form last post) and add the following variables:

Additionally, add DbUser, DbPassword, and QueueConnectionString as secret variables to the pipeline. These variables contain the database user and password and the connection string to the Azure Service Bus Queue. If you want to deploy your own Azure Function without a connection to other services, then you obviously don’t have to add the variables.

Next, add a job inside a stage and create a build version using GitVersion. If you want to learn more about versioning, see my post Automatically Version Docker Containers in Azure DevOps CI.

With the version number in place, add two more tasks to build the Docker container and then push it to a registry. In this demo, I am pushing it to DockerHub.

The last step is to deploy the previously created Docker container to the Azure Function and then pass the database and queue connection string to its settings. For more information about deploying an Azure Function with Azure DevOps see my last post, Deploy Azure Functions with Azure DevOps YAML Pipelines. Note that the Azure Function must exist, otherwise the deployment will fail.

The full pipeline looks as follows:

Save the pipeline and run it.

The pipeline ran sucessfully

The pipeline ran sucessfully

You can see the Docker container with its two tags on DockerHub after the build is finished.

The Azure Function Container got pushed to DockerHub

The Azure Function Container got pushed to DockerHub

Testing the Azure Function is exactly the same as in my last post, Deploy Azure Functions with Azure DevOps YAML Pipelines.

Conclusion

This short post showed how to create a Docker container of an Azure Function inside an Azure DevOps YAML pipeline. The Docker image was published to DockerHub and then deployed to an existing Azure Function.

You can find the code of the demo on Github.

This post is part of “Microservice Series - From Zero to Hero”.

This post is licensed under CC BY 4.0 by the author.