Solution 1:

This Stack Exchange Q&A has various ways of setting LD_LIBRARY_PATH the top voted answer suggests this is the best way:

sudo -H gedit /etc/ld.so.conf.d/randomLibs.conf

inside the file you are supposed to write the complete path to the directory that contains all the libraries that you wish to add to the system, for example

/home/linux/myLocalLibs

remember to add only the path to the dir, not the full path for the file, all the libs inside that path will be automatically indexed.

Save and run sudo ldconfig to update the system with this libs.

Solution 2:

Do you have to export the LD_LIBRARY_PATH? can't you just preface the matlab call with it, e.g.

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/MATLAB/MATLAB_Runtime/v94/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/extern/bin/glnxa64 /usr/local/MATLAB/MATLAB_Runtime/...

(I do not exactly know what the executable is called like)

You could put that in a little skript

Secondly, it could be possible to change the rpath of the executable or some library, so it looks at the correct place directly. I use patchelf for this

patchelf --set-rpath 

Since there are multiple paths involved it could get a bit tricky, though

Solution 3:

The only way it worked for me is by defining LD_PRELOAD and point it to system library. So my current environment would be:

LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v94/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/extern/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/sys/opengl/lib/glnxa64
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libexpat.so

So in docker, I have created a .matlab file that contains the mentioned env variables. Then, in dockerfile I added the following:

services:
  django: &django
    build:
      context: .
      dockerfile: ./compose/local/django/Dockerfile
    depends_on:
      - postgres
    volumes:
      - .:/app
      - shared_upload_tmp:/app_temp
      - media:/app/computation_server/media
    env_file:
      - ./.envs/.local/.django
      - ./.envs/.local/.postgres
      - ./.envs/.production/.matlab
    ports:
      - "8800:8000"
    command: /start