How can I install libgdiplus apt package on Linux Azure Function startup command?

Viewed 793

We have a .NET Core 3.1 function running on Linux Azure Function App, but because it uses System.Drawing library it depends on libgdiplus which is not installed in the default docker image, so the function fails.

enter image description here

I read a lot articles suggesting to add the following startup command in the Function App, but it's not working, it's simply not installing the package.

enter image description here

apt-get update && apt-get install -y --allow-unauthenticated apt-utils libc6-dev libgdiplus libx11-dev && rm -rf /var/lib/apt/lists/*

I saw this on the docker logs but still the package is not there.

docker run -d -p 8122:80 --name <image-name> -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=true -e WEBSITE_SITE_NAME=<website-name> -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=<hostname> -e WEBSITE_INSTANCE_ID=<instanceId> -e HTTP_LOGGING_ENABLED=1 mcr.microsoft.com/azure-functions/dotnet:3.0-appservice-stage5 apt-get update && apt-get install -y --allow-unauthenticated apt-utils libc6-dev libgdiplus libx11-dev && rm -rf /var/lib/apt/lists/*

I can install the packages manually by opening a SSH sesion on the Azure Portal and running the command, and run the function succesfully, but obviousy next time it's restarted, the package is gone because the container is restarted as well.

Any other options or any help to troubleshoot this will be highly appreciated.

Thanks!

1 Answers

I think the proper way to do this would be to have your own custom Dockerfile that runs the apt-get commands you've provided.

Here's a snippet of what that would look like:

FROM mcr.microsoft.com/azure-functions/dotnet:3.0-appservice-stage5

RUN apt-get update \
    && apt-get install -y --allow-unauthenticated \
      apt-utils \
      libc6-dev \
      libgdiplus \
      libx11-dev \
    && rm -rf /var/lib/apt/lists/*

Further details on how to use custom Docker container with Azure Functions are found in the docs.

Related