How and why use Azure Functions with Docker (2023)

You probably have heard about Azure Functions and Docker since they are becoming more and more popular every day. Here you will learn what they are and why they go great together! Plus a step-by-step tutorial on how to get started using them.

Ignacio Boada



13 min read


Sep 14, 2019


This post presents an overview of what Azure Functions and Docker are, and a step-by-step guide on how to start using Azure Functions With Docker

Let’s say you have a great idea for an application and you have some programming skills. So, you just want to write your code and show your product to the world. Well… you will find that is not so easy, you need servers, frameworks, and more.. Until NOW! With Azure Functions you can just code without having to worry about servers and all that, and with Docker you can run the same applications everywhere. That’s why these two make such a great team!

Let’s start by learning a little bit about what Azure Functions and Docker are. Along the way you will find some links about different subjects in case you are interested in deepening your knowledge about them.

How and why use Azure Functions with Docker (2)

Let’s see, what is Azure Functions? Azure Functions is a solution for easily running small pieces of code, or “functions,” in the cloud. Azure Functions acts as a modern serverless architecture delivering event driven cloud computing and configured to comply with application development.

If you don’t like reading so much, here is a short video (less than 2 minutes!) on Azure Functions.

Azure Functions is a great solution for processing data, integrating systems, working with the internet-of-things (IoT), and building simple APIs and microservices.

Some of the main benefits are:

  • End-to-end development experience
  • Variety of programming languages and hosting options
  • No need for server maintenance.
  • Automated and flexible scaling based on your workload volume
  • Integrated security
  • Open-source

And much, much more. You can read more about these benefits and Azure Functions on the official documentation web page.

Docker is here to save us from having to create different codes for different platforms, and to avoid hours of troubleshooting trying to figure out why an application doesn’t work on some computers. Thanks to Docker, if an application works on a computer, it will surely work on any computer.

How and why use Azure Functions with Docker (3)

But, what is docker? Docker is a tool that lets you create, deploy, and run applications by using containers. Okay, but what are containers and what’s so great about them? Technically a container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. This means that you have everything that your application needs to run on a big box that you can share, and when that box is open on another computer, everything in it will work just like it did on your computer, regardless of operating system or any particular configuration.

If you have worked on a team project, you know this would have solved many problems, like everyone wanting to use THEIR favorite OS taking hours of discussion between team members on why one OS is better than other. So, it’s not just a solution for deploying applications on final users, but it also helps developers.

How and why use Azure Functions with Docker (4)

Now, you might be thinking, “Hey, this reminds me of Write once, run anywhere from Java, so, are containers Virtual Machines?”. The answer to that question would be, No. What Virtual Machines do is recreate a whole operating system on top of the hosting operating system, which takes a lot of resources, while Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size).

How and why use Azure Functions with Docker (5)

To understand a little bit more why Containers are better than Virtual Machines (VM) when trying to run apps, you can say that a VM is essentially an emulation of a real computer that executes programs like a real computer, while a container provides operating-system-level virtualization by abstracting the “user space”.

How and why use Azure Functions with Docker (6)

This diagram shows you that containers package up just the user space, and not the kernel or virtual hardware like a VM does. Each container gets its own isolated user space to allow multiple containers to run on a single host machine. You can see that all the operating system level architecture is being shared across containers. The only parts that are created from scratch are the bins and libs. This is what makes containers so lightweight. This is just a little summary. If you are interested in deepening your knowledge on the difference between VMs and Containers I highly recommend you read this post.

Now that you know what Azure Functions and Docker are, you can see why they go so well together!

How and why use Azure Functions with Docker (7)

The next step is to start using them!

NOTE: The installation process will be done on a 64-bits Windows 10 Home Edition operating system.

  1. Installing Docker
  • If you have 64 bits Win 10 64 Pro or Enterprise Edition, the installation process it’s fairly simple, just click here and in the opened tab click “Download Desktop for Mac and Windows”, this will open a new tab where you should click on “Get Started with Docker Desktop”, this will open a step-by-step tutorial that you should just follow. (I don’t go into much detail on this tutorial sin I don’t have Win 10 Pro nor the Enterprise Edition. The installation on Windows 10 Home Edition is more detailed).
  • If you have 64 bits Windows 10 Home Edition, Docker Desktop is not supported. If you try to install it you will get the following error:
How and why use Azure Functions with Docker (8)

Luckily, Docker offers the Docker Toolkit which is very similar to Docker Desktop but with a different interface.

With Docker Toolbox you will get the following Docker tools:

  • docker
  • docker-machine
  • docker-compose
  • Kitematic
  • Boot2Docker ISO
  • VirtualBox

Why are so many things needed? Because the Docker Engine daemon uses Linux-specific kernel features, you can’t run Docker Engine directly on Windows. Instead, you must use the Docker Machine command, to create and attach to a small Linux VM on your machine. This VM hosts Docker Engine for you on your Windows system.

To download it, click here. On the opened tab you will see that there are a lot of different versions of the Docket Toolkit, just install the latest one (in my case is version 19.03.1). Please ensure that your system has all of the latest updates before attempting the installation.

How and why use Azure Functions with Docker (9)

From here is pretty straight forward. Select where you want to save the file. Double click on the .exe file once it’s downloaded. Select where to install it (like any other program) and click on Next until it finishes with the installation process. If everything went well the following sign should pop up. Click on Finish.

How and why use Azure Functions with Docker (10)

Once you clicked on Finish, you should see a folder with these applications. Open “Docker Quickstart Terminal”

How and why use Azure Functions with Docker (11)

A terminal will appear, don’t be scared, it’s just the initialization process to get docker running on your computer for the first time. This will take a couple of minutes, and when it’s set up, you will see the iconic Docker Whale in the terminal, this means that everything went well. Cheers!

How and why use Azure Functions with Docker (12)

To make sure that there is no problem, you can run the following command line (and your first command line in the Docker terminal!):

docker run hello-world

At first it will say it’s unable to find the image, but don’t panic, just wait a little while and Docker will find it automatically. You should see something like this in your terminal if everything is okay:

How and why use Azure Functions with Docker (13)

Well done!

2. Quickstart on Azure Functions

To be free from using any IDE, we will use the Command Line to create our Azure Function.

First you need to Install Node.js, which includes npm. You can find it here. Download the .msi file and double click it. The installation process is very easy, just click Next, Next, Next and Install. If there were no problems, you should see something like this. Click on Finish.

How and why use Azure Functions with Docker (14)

Then open a terminal and Change directories until you are in your nodejs directory. There run the following line:

npm install -g azure-functions-core-tools

You should see something like this. If there are no errors, it means everything went well.

How and why use Azure Functions with Docker (15)

This will install the Core Tools package in your system.

The next step is installing the .NET Core 2.x SDK for Windows. You can find it here. Since we want to Build Apps, the “Build Apps” download should work fine (We won’t be using Visual Studio, so just click on the “Download .NET Core SDK”).

How and why use Azure Functions with Docker (16)

When the file finishes downloading, double click it, and click Install. Once it’s installed you should see this:

How and why use Azure Functions with Docker (17)

Since we want to use the Command Line to create Azure Functions, we need to install the Azure CLI. The Azure CLI is a command-line tool providing a great experience for managing Azure resources. The CLI is designed to make scripting easy, query data, support long-running operations, and more. To download it, go to this link and click on the “Download the MSI installer” button.

How and why use Azure Functions with Docker (18)

Like all other installations, double click on the downloaded file, accept the terms and conditions and hit Install. It will prompt for permissions, press Yes.

You should see this if everything went okay:

How and why use Azure Functions with Docker (19)

That was easy!

Finally, if you want, you can create an Azure account. You’ll need this if you want to upload your function to your Azure Portal.

3. Getting started

Now that you have everything installed, it’s time to create your project.

Since many of you probably decided that you didn’t want to give your credit card information until you are 100% sure that Azure Functions are really useful, let’s begin by creating a function locally.

First Create a folder where you want your project to be. Then open a Command Prompt by writing “cmd” on windows search, and go to that folder on the Terminal. In my case my project will be in “C:\Users\Nacho\FirstAzureFunctionWithDocker”

Now run the following command:

func init --docker
How and why use Azure Functions with Docker (20)

Select a worker runtime from the following language choices (use the arrow keys to move, enter to select):

I chose dotnet because I will create my function in C#. I recommend you follow my steps for your first function, since there are differences in the creation process between each option. Once you understood the first steps, just then, you can spread your wings and fly on your own.

You will see that many files where created on your project folder. These are all the files needed for the project.

How and why use Azure Functions with Docker (21)

As you can see, a Dockerfile was created on the project folder. This file is used to create a custom container for your project. This is all you need to add Docker to you Azure Functions. Now you can focus on Azure.

On the Command Prompt type func new

How and why use Azure Functions with Docker (22)

You will see a list of possible Template to select. Here’s a short description of the main ones:

To see more on templetes you can go to the Azure Functions Overview webpage.

I will use the HTTPTrigger template since it’s the easiest one to start using Azure Functions.

Once you’ve selected the template, you will have to choose a function name. I named my function “FirstAzureFunctionWithDockerFunction”.

How and why use Azure Functions with Docker (23)

You have created your first function!

Let’s check the code. On your project folder open the .cs file (by the way, I like to use notepad++, it’s a fast and very powerful tool that supports almost all programming languages).

Look at all the code you have, and you haven’t written a single line. Templates are just great!

How and why use Azure Functions with Docker (24)

If you want to share your functions, you can always use GitHub. I uploaded my project to this GitHub repository.

To make things easier to use, change the AuthoritationLevel on line 17 from “Function” to “Anonymous”, this way you won’t have to remember which key you assigned or anything. If you are interested in Authoritation levels, you can learn all about them here.

Now you can call the function without having to supply the function key (The function key is never required when running locally, but it will be in a Docker Container).

Let’s go back to containers. You want to run your function on a container. To achieve this you need to build an image of your function.

Open “Docker Quickstart Terminal” and go to the “Docker Toolbox” folder. There run this line (imageName is the name that you want for your Docker image):

docker build -t <imageName> Path_to_the_project

I called my image “firstimage”. Note that images names must be in lowercase.

How and why use Azure Functions with Docker (25)

The building process might take a while, be patient.

The next step running the image that you created. Run the following command , still on the “Docker Tools” folder:

docker run -p <port> <imageName>

To avoid conflicts I recommend you use the port 8080:80. If there are no problems, you should see something that starts and ends like the following images:

How and why use Azure Functions with Docker (26)
How and why use Azure Functions with Docker (27)

And with this you have the custom image running in a local Docker container!

Now you can see the execution of your function directly on an internet browser. To do this all you need to do is to write this on the URL:

http://<docker-machine ip>:<port>/api/<functionName>?name=<yourName>

To find the ip of your docker-machine, just excecute docker-machine ip. This is just for those who have Docker Toolbox. If you have Docker Desktop you type “localhost” instead.

How and why use Azure Functions with Docker (28)

The template Function shows me this.

How and why use Azure Functions with Docker (29)

And that’s it!

Now you know what Azure Function and Docker are, and the whole process on how to use Azure Functions with Docker!

But this is just the beginning, Azure Functions and Docker have much more to offer, and trust me, it’s in your best interest to know as much as you can about these technologies because they are the future. They are growing fast, becoming popular, and making life easier to everyone.

I recommend you to complement this tutorial by reading the official documentation on Azure Functions. The information is clear, precise, and up to date since they are the ones who make changes. I think that Investigating more on what can you do with Azure Functions is the next step, since it will help you understand the huge potential of Azure Functions. So, click here and start your way into becoming an Azure Functions expert!

With great knowledge on Azure Functions, and the capability of using containers to share you developments, you will be unstoppable!

Another choice is to watch educational videos. In my opinion videos are more friendly and easy going than long texts. If you like videos too, I highly recommend this series. Mostly short videos, so that you don’t become overwhelmed, and with continuous growth on subjects, so that you don’t have to start over every time as it normally happens with isolated tutorials.

To keep going, if you are interested in the serverless features that Azure provide, you can what this video.

Or maybe containers just blew your mind and want to go deeper in that area, you can read this article.

On the internet there is a tremendous amount of information. Don’t be anxious, don’t try to read and know absolutely everything. Focus on some tutorials, and remember that it’s better to learn a lot from a few than little from many.

Thank you very much for reading my post!

I hope you learned a lot and enjoy yourself while doing it. I am sure this knowledge will be of great use in your future.

Feel free to share it with your colleagues and friends, and maybe this is the first step towards your own team project!

Top Articles
Latest Posts
Article information

Author: Allyn Kozey

Last Updated: 06/28/2023

Views: 6426

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.