title: How to install both MATLAB MCR and the dotnet runtime in a Docker container?
body: <p>I am trying to create a Docker container where I can use <code>dotnet</code> to run a C# program that loads a MATLAB Runtime (<a href="https://www.mathworks.com/products/compiler/matlab-runtime.html" rel="nofollow noreferrer">MCR</a>) DLL to process some data. (.net core 3.1, MATLAB 2014b)</p>
  <p>I have created an image based on the official dotnet image for Ubuntuthat installs the MATLAB's MCR runtime in accordance with an <a href="https://github.com/flywheel-apps/matlab-mcr/blob/master/2014b/Dockerfile" rel="nofollow noreferrer">example</a> I've found online. Here is my <code>Dockerfile</code>:</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/core/runtime:3.1-focal 
  ARG DEBIAN_FRONTEND=noninteractive
  
  RUN apt-get -qq update &amp;&amp; apt-get -qq install -y \
      unzip \
      xorg \
      wget \
      curl &amp;&amp; \   
      mkdir /mcr-install &amp;&amp; \
      mkdir /opt/mcr &amp;&amp; \
      cd /mcr-install &amp;&amp; \
      wget http://ssd.mathworks.com/supportfiles/downloads/R2014b/deployment_files/R2014b/installers/glnxa64/MCR_R2014b_glnxa64_installer.zip &amp;&amp; \
      unzip -q MCR_R2014b_glnxa64_installer.zip &amp;&amp; \
      ./install -destinationFolder /opt/mcr -agreeToLicense yes -mode silent &amp;&amp; \
      cd / &amp;&amp; \
      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
  
  </code></pre>
  <p>When I run the container interactively and try to run <code>dotnet</code> in it I get this error:</p>
  <pre><code>❯ 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
  </code></pre>
  <p>It seems that the last line in my <code>Dockerfile</code> - the one that sets <code>LD_LIBRARY_PATH</code> - is essential for the MCR runtime but disrupts the <code>dotnet</code> executable.</p>
  <p><strong>How can I work around this issue?</strong></p>
  <p>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.</p>