'How to deploy nodejs Azure function to azure with docker?

This is my first time playing with azure. I have a simple tool written which has to fetch some data from the postgres db, and send it to a MS teams channel. All my files are in a simple folder like this. Folder structure

I want to know how do I deploy this? (Not the vscode way). I believe it's via docker? Where I create an image and push it to azure.

DockerFile

this is how my dockerfile looks. Whenever I build it and run the docker file throws various errors. My index.ts looks like this. I believe I am doing some very simple mistakes. I cannot find a tutorial online where it shows me this process. Please let me know where I am going wrong. Thanks. index.ts



Solution 1:[1]

Creating a Dockerfile

  • The easiest way to create a Dockerfile for an Azure Function app is to install the Azure Functions Core Tools (you will need v2), and run the func init --docker command.
  • This will prompt you for what worker runtime you want
  • base image used - for node is microsoft/azure-functions-node8.
  • Please find the below workaround of Dockerfile it creates for a node Function App. It simply sets an environment variable and then copies everything in to the home/site/wwwroot folder.
FROM microsoft/azure-functions-node8:2.0  ENV
AzureWebJobsScriptRoot=/home/site/wwwroot 
COPY . /home/site/wwwroot

Build and run locally

  • Issue a docker build command, and give it a name and tag:
docker build -t myfuncapp:v1 . 
  • Expose a port if you have HTTP triggered functions, and set up any environment variables to connection strings your function needs:
docker run -e MyConnectionString=$connStr -p 8080:80 myfuncapp:v1 
  • You can easily get Docker Imagerun in Azure, with Azure Container Instances and the Azure CLI (ACI and Azure CLI).
  • The container needs two environment variables - one to tell it the connection string of the storage account, and one to tell our proxy where to find the static web content,

Please refer Run Azure Functions in a Docker Container for more information

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HarshithaVeeramalla-MT