Dapr and Azure Functions: Part 2 – Azure Functions Containerization in Docker

In Part 1, we created the basic Functions Hello World app.

At this point, Dapr and Functions are running in separate processes on the local machine with Dapr acting as a forwarding proxy.

Now our goal is to containerize the whole thing by starting with the Functions app first.

Step 1: Setup Docker Account and Add Dockerfile

if you haven’t already, you need to go into Docker Hub and set up your account.  Once you’ve set it up, log into your account on Docker Desktop.

Since we didn’t add a Dockerfile when we created the Function, we need to do that now with the following command:

func init --docker-only

This will create the default Dockerfile:

Step 2: Build Docker Image

I’m following along with the Microsoft article Create a Custom Linux Image.

We need to execute the command:

docker build --tag cdigs/azurefunctionsimage:v3 .

NOTE: Take note of the . at the end of that command!

Replace cdigs with your Docker Hub account ID.

This will take docker a bit of time to pull down the necessary image.

Once it’s done, you’ll be able to see it in Docker Desktop:

Step 3: Run Docker Image

We can run the docker image 2 ways: by clicking the Run button in Docker Desktop or executing the following command from Visual Studio:

docker run -p 8181:80 -it cdigs/azurefunctionsimage:v3

Let’s break this down:

  1. docker run -p 8181:80 instructs docker to expose the port 8181 on the container and map that to port 80 on the Function app.
  2. -it cdigs/azurefunctionsimage:v3 identifies the image to run

In Visual Studio Code, we should see the following as the Functions runtime starts up:

We can hit the Function endpoint via the URL: http://localhost:8181/api/helloworld

Our Function app is now in a container and conceptually looks like this:

Note that there is no Dapr at this point what-so-ever.

Next Part

Now to add Dapr to our container!

You may also like...

2 Responses

  1. July 2, 2021

    […] Part 2 – Azure Functions Containerization in Docker […]

  2. July 2, 2021

    […] In Part 2, we created the Dockerfile and deployed the Functions app to a container. […]

Leave a Reply

Your email address will not be published. Required fields are marked *