How to create docker image from Azure Function?

If you are already working with Azure Functions to build serverless components, you are probably happy with hosting options, which Microsoft Azure provides.
However, sometimes you want to run your function somewhere else. For example On-Edge or even in some other cloud.
Easiest way to do this is to create a docker container from function.

func init . --docker 

Unfortunately, this command should only be used before you create your Azure Function project. For example, like this:

func init . --docker 
func new 

In this case, we already have create function and have following situation:

func new 
func init . --docker 

When you execute 'func init' you will get following warning:

Creating this template will make changes to existing files:
  Overwrite   .gitignore
  Overwrite   myfnc.csproj
  Overwrite   host.json
  Overwrite   local.settings.json

Rerun the command and pass --force to accept and create.

You should be careful with this, because it will damage your project files.
In my case it has removed:

  1. Reference to Service Bus Extensions
<PackageReference 
      Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.0.3" />
  1. Settings added manually to local.settings.json.

But you can workaround this, if you simply execute docker init in some empty folder and then copy newly created dockerfile to your project folder.


comments powered by Disqus