Azure-docs: Documentation needed on how to run functions that use bindings extensions in a docker container

Created on 13 Nov 2018  ·  8Comments  ·  Source: MicrosoftDocs/azure-docs

The simplest of functions (http and timer) do not require the .net core dlls installing. if you use queue, blob storage triggers, you have to run func extensions install before you run the function to install the necessary bindings. How to do this with docker is not covered in your tutorials. Please advise


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author azure-functionsvc doc-enhancement triaged

Most helpful comment

Looking forward to this coming to fruition 👍

All 8 comments

Hi @GuyHarwood Thank you for your feedback! We have assigned this issue to the author to investigate further and take the right course of action.

The following worked for me:

  1. Add something like type="queue" or type="queueTrigger" to function.json
  2. Use func extensions install locally to create extensions.csproj (I think this utility parses your function.json files)
  3. Add a build step to build the project: dotnet build -o bin
  4. Make sure the bin directory gets added to your container in your Dockerfile. I use COPY . . so everything gets added.

For build, I'm using Azure Pipelines, so I added this task:

- task: DotNetCoreCLI@2
  inputs:
    command: custom
    custom: build
    arguments: -o bin

The cleanest approach (IMO) to this, is to use an intermediary container during docker build to install the binding extensions, then just copy the final sources to the official functions container. That way your build server (we use AzureDevOps & Travis) is kept clean...

### STAGE 1: Build ###
FROM node:10.6.0 as builder

SHELL ["/bin/bash", "-c"]

WORKDIR /func-app
COPY . .
RUN yarn install
# install .net core, azure functions core tools & required bindings
RUN apt-get update && \
    curl -O https://dot.net/v1/dotnet-install.sh && \
    source dotnet-install.sh --channel Current && \
    rm dotnet-install.sh && \
    npm i -g azure-functions-core-tools@core --unsafe-perm true && \
    func extensions install

### STAGE 2: functions runtime image ###
FROM mcr.microsoft.com/azure-functions/node:2.0

ENV AzureWebJobsScriptRoot=/home/site/wwwroot
COPY --from=builder /func-app /home/site/wwwroot

This is working well for us in Travis and AzureDevOps / VSTS

@dariagrigoriu or @ahmelsayed can you please confirm what the best approach is for adding extensions to a function app in a custom Docker container? We either need to document this in a separate article or change the scenario to use a trigger other than HTTP.

Looking forward to this coming to fruition 👍

I think that extension bundles solves this issue. Let me confirm.

I tried the extension bundle in my host.json and it seemingly fixed this issue.

My host.json looks like this:

{
    "version":  "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}

We've updated the original tutorial to show how to add an output binding to the function project and rebuild the container. #please-close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulmarshall picture paulmarshall  ·  3Comments

mrdfuse picture mrdfuse  ·  3Comments

bdcoder2 picture bdcoder2  ·  3Comments

Favna picture Favna  ·  3Comments

bityob picture bityob  ·  3Comments