How to choose specific Linux version for Azure function running in Docker

Andrew Menzies 0 Reputation points
2023-01-23T22:00:12.2466667+00:00

Brief question: Is there a way, using Docker, I can choose which version/distribution of Linux my Azure function app runs on? I'm deploying the app as a Docker image. Guides to Docker say if I want a container to run in a particular version of Linux, I would have to choose a base image that includes that version. But guides to Azure Functions that use Docker, such as Create a function on Linux using a custom container, all say I have to start with one of the Azure Functions-specific images, such as "mcr.microsoft.com/azure-functions/dotnet:4", of which there aren't very many choices and none of them mention a Linux version. So I'm not sure how to resolve the impasse.

The reason I need a particular version of Linux is because the Chromium library used for HTML-to-PDF conversion (the purpose of my function) is only known to work under certain versions of Linux, such as CentOS 8, but the function is currently using Debian GNU/Linux 11 (bullseye).  

Full story: My goal is to create a function that uses PDFTron's HTML2PDF library to create PDFs. I am able to get the library working if I create a Linux function manually through Visual Studio Code's Azure Functions extension. However, when I create a Linux function through the Azure portal, the az command tools, or Octopus Deploy, the library does not work, and it seems to be because the Linux OS in these cases is missing a few essential libraries: libnss3 and libnspr4.

Therefore, I decided to instead create a function that runs in a Linux Docker container; that way I can run apt-get while creating the container to install the missing dependencies. This does what I want and installs the missing dependencies; I can use lss to see that the HTML2PDF library can find every package it needs to run. But even so, it doesn't seem to be compatible with the Linux version that the function is running on.

The dockerfile looks like this:

FROM mcr.microsoft.com/azure-functions/dotnet:4
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY ["./bin/Release/net6.0/publish", "/home/site/wwwroot"]
RUN apt-get -y update
RUN apt-get -y install libnss3
# RUN apt-get -y install libnssutil3 (This is not needed as it is part of libnss3)
RUN apt-get -y install libnspr4

(Note that I run dotnet publish beforehand and simply copy the result (from the bin/Release/net6.0/publish folder) into the container rather than calling dotnet publish from the Dockerfile.) If there's a step I can add to change the Linux version, or a base image that can replace mcr.microsoft.com/azure-functions/dotnet:4 but will still allow the function to run, please let me know.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,015 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andriy Bilous 10,731 Reputation points MVP
    2023-01-24T16:00:25.08+00:00

    Hello @Andrew Menzies

    Here is the link to Microsoft Official Azure Function Docker images: https://github.com/Azure/azure-functions-docker

    All Azure Function v4 Docker images are based on Debian 11.
    Microsoft recommends to use only official images to run Azure Function as custom image.
    When using custom containers, you are required to keep the base image of your container updated to the latest supported base image

    Do you get a specific error if you run your app in custom Docker container?

    FROM mcr.microsoft.com/azure-functions/dotnet:4
    ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
        AzureFunctionsJobHost__Logging__Console__IsEnabled=true
    
    COPY ["./bin/Release/net6.0/publish", "/home/site/wwwroot"]
    RUN apt-get -y update
    RUN apt-get -y install libnss3
    # RUN apt-get -y install libnssutil3 (This is not needed as it is part of libnss3)
    RUN apt-get -y install libnspr4
    
    
    0 comments No comments