Azure Functions on a Docker Container
Ever wanted to run a small piece of code on the cloud without worrying about the infrastructure and server maintenance? Then Azure Functions may be what you are looking for! In this step-by-step guide we will learn how to deploy a simple HTTP Trigger on a Docker Container, which will allow us to have full control of the runtime environment and get total abstraction from the OS.
As a prerequisite, you will need to download Node.js 8.5 or greater, Azure CLI, Azure Functions Core Tools, and have Docker running on your computer.
Once you have those installed, we can start with the proper tutorial.
The first thing you have to do is open a Terminal, and run the following:
>func init . --docker
>func new
>2
>2
>
Before building the Docker Image, make sure to edit function.json
and change authLevel
to anonymous
.
Once that is done, you can run docker build -t MY_FUNCTION .
and docker run -p 8080:80 MY_FUNCTION
to deploy your function.
Now if you open a browser and go to http://localhost:8080 you should see something like this:
You could also test your function by going to http:localhost:8080/api/HttpTriggerJS?name=MY_NAME and you should see something like this:
You can find the whole example on https://github.com/jpdantur/azure_demo.
For more examples, you can check https://cmatskas.com/running-azure-functions-anywhere-with-the-power-of-containers/ and https://blog.wille-zone.de/post/run-azure-functions-in-docker/.