How to install both MATLAB MCR and the dotnet runtime in a Docker container?

I am trying to create a Docker container where I can use dotnet to run a C# program that loads a MATLAB Runtime (MCR) DLL to process some data. (.net core 3.1, MATLAB 2014b)

I have created an image based on the official dotnet image for Ubuntuthat installs the MATLAB’s MCR runtime in accordance with an example I’ve found online. Here is my Dockerfile:

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get -qq update && apt-get -qq install -y 
    curl &&    
    mkdir /mcr-install && 
    mkdir /opt/mcr && 
    cd /mcr-install && 
    wget && 
    unzip -q && 
    ./install -destinationFolder /opt/mcr -agreeToLicense yes -mode silent && 
    cd / && 
    rm -rf mcr-install

ENV LD_LIBRARY_PATH /opt/mcr/v84/runtime/glnxa64:/opt/mcr/v84/bin/glnxa64:/opt/mcr/v84/sys/os/glnxa64:/opt/mcr/v84/extern/bin/glnxa64

When I run the container interactively and try to run dotnet in it I get this error:

❯ docker run -it dotnet-mcr:0.2 /bin/bash
[email protected]:/# dotnet --info
Failed to load ���, error: /opt/mcr/v84/sys/os/glnxa64/ version `GLIBCXX_3.4.18' not found (required by /usr/share/dotnet/host/fxr/3.1.10/
The library was found, but loading it from /usr/share/dotnet/host/fxr/3.1.10/ failed
  - Installing .NET Core prerequisites might help resolve this problem.

It seems that the last line in my Dockerfile – the one that sets LD_LIBRARY_PATH – is essential for the MCR runtime but disrupts the dotnet executable.

How can I work around this issue? (Please bear in mind that I need to run my MCR DLL in a C# program)

Source: Docker Questions