Home Deploy a Docker Container to Azure Functions using an Azure DevOps YAML Pipeline
Post
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.

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

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 from my 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 Docker Hub.

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 successfully

The pipeline ran successfully

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

The Azure Function Container got pushed to Docker Hub

The Azure Function Container got pushed to Docker Hub

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 Docker Hub 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.

Deploy Azure Functions with Azure DevOps YAML Pipelines

Set up Nginx as Ingress Controller in Kubernetes

Comments powered by Disqus.