The new Azure Functions on Linux preview enables local Azure Functions development on Linux and Mac platforms to seamlessly translate to cloud hosting on Linux across a broader choice of hosting options. The Linux hosting model for Azure Functions is based on Docker containers which brings greater flexibility in terms of packaging and leveraging app specific dependencies. This is another stepping stone in the journey to run Azure Functions anywhere and to enable reuse of your Function App code assets.
Functions on Linux can be hosted in a dedicated App Service tier in 2 different modes:
- You bring the Function App code and we provide and manage the container, no specific Docker related knowledge required.
- You bring your own Docker container including the Azure Functions runtime 2.0, specific dependencies, and Function App code.
Please note that charges for the dedicated App Service Plan you select will apply to the preview as published on the App Service pricing page.
With the Azure Functions on Linux preview you should be able to run any Azure Functions scenarios supported by the Azure Functions runtime 2.0. Notes for known Azure Functions runtime 2.0 limitations are available at this link. Support for the Azure Functions on Linux preview is available with the Azure Portal and the Azure CLI. This blog post will focus on the Azure CLI for creating Azure Functions resources. The following steps are required regardless of the hosting mode selected:
- Install the latest version of the Azure CLI.
- Run az login to access your Azure account.
- Create Azure resources:
# Create a Resource Group az group create -n rg-name -l "South Central US" # Create a Linux App Service Plan (use S2 or S3 as the sku value for larger VMs) az appservice plan create -n plan-name -g rg-name --is-linux -l "South Central US" --sku S1 --number-of-workers 1 # Create a storage account az storage account create -n storage-name --location "South Central US" --resource-group rg-name --sku Standard_LRS
Host Function App content via an App Service managed container
To host Function App content via an App Service managed container first create a Linux Function App:
# Create a Linux Function App az functionapp create -n fun-app-name -g rg-name -p plan-name -s storage-name
You can manage the Function App in the Azure Portal and deploy Function App content using your preferred workflow. Read more about this hosting mode in our App Service managed container for Azure Functions documentation.
Host a custom Azure Functions container
To create a Function App pointing to a specific container image use the example below (referencing the latest Azure Functions on Linux starter image):
# Create a Linux Function App pointing to a specific container image az functionapp create -n fun-app-name -g rg-name -p plan-name -i microsoft/azure-functions-runtime:2.0.0-jessie -s storage-name
You can manage the Function App in the Azure Portal. The Function App content however is not editable in the Azure Portal when using a custom container.
To create your own container image, you must install a few prerequisites:
- .NET Core 2.0
- The latest azure-functions-core-tools: npm i -g azure-functions-core-tools@core
Please note that app specific configuration can be included in the Dockerfile or managed as App Settings for the Function App. Once the prerequisites are installed you can follow these steps:
- Create a Function App directory locally.
- Generate a Dockerfile and optionally a sample function:
func init . --docker --sample func start
- Build your container image and optionally test your Function App running in a container locally:
docker build -t my-functions. docker run -p 8080:80 my-functions
- Publish your container image to an online registry such as Docker Hub:
docker login docker tag my-functions my-repo/my-functions docker push my-repo/my-functions
Read more about this hosting mode in our custom Azure Functions containers documentation.
You can also run your Function App in a container on other container-based hosting platforms such as Azure Container Instances:
az container create --name <your name="" container=""> --image <your alias="" hub="" docker="">/<your name="" image=""> --resource-group <your name="" group="" resource=""> --ip-address public
Known issues for this preview are listed on the Azure Functions wiki. To ask questions or share issues with the engineering team for the Azure Functions on Linux preview please use the Azure Functions MSDN forum.