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
:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-focal
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update && apt-get -qq install -y \
unzip \
xorg \
wget \
curl && \
mkdir /mcr-install && \
mkdir /opt/mcr && \
cd /mcr-install && \
wget http://ssd.mathworks.com/supportfiles/downloads/R2014b/deployment_files/R2014b/installers/glnxa64/MCR_R2014b_glnxa64_installer.zip && \
unzip -q MCR_R2014b_glnxa64_installer.zip && \
./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
root@1e15419d3fee:/# dotnet --info
Failed to load ���, error: /opt/mcr/v84/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by /usr/share/dotnet/host/fxr/3.1.10/libhostfxr.so)
The library libhostfxr.so was found, but loading it from /usr/share/dotnet/host/fxr/3.1.10/libhostfxr.so failed
- Installing .NET Core prerequisites might help resolve this problem.
https://go.microsoft.com/fwlink/?linkid=2063370
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?
Note: As @jdweng commented below, upgrading to a more recent version of MATLAB could likely solve the issue by aligning the versions of the clashing DLLs. I would appreciate, if possible, a solution that does not involve upgrading.
As @jdweng wrote in a comment to my question - The solution is to use .Net and MATLAB versions that depend on the same version of C++ shared objects.
In my case this means .Net Core 3.1 and MATLAB 2020b (v99). Below is the Dockerfile that works for me (again, based on Michael Perry's example).
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-focal
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update && apt-get -qq install -y \
unzip \
xorg \
wget \
curl && \
mkdir /mcr-install && \
mkdir /opt/mcr && \
cd /mcr-install && \
wget https://ssd.mathworks.com/supportfiles/downloads/R2020b/Release/3/deployment_files/installer/complete/glnxa64/MATLAB_Runtime_R2020b_Update_3_glnxa64.zip && \
unzip -q MATLAB_Runtime_R2020b_Update_3_glnxa64.zip && \
./install -destinationFolder /opt/mcr -agreeToLicense yes -mode silent && \
cd / && \
rm -rf mcr-install
ENV LD_LIBRARY_PATH /opt/mcr/v99/runtime/glnxa64:/opt/mcr/v99/bin/glnxa64:/opt/mcr/v99/sys/os/glnxa64:/opt/mcr/v99/extern/bin/glnxa64