Slim installation of MATLAB Runtime
Show older comments
I want to create a Docker image with MATLAB Runtime and a compiled MATLAB executable. The executable only uses core MATLAB, so I do not want to install every available product because that will make the Docker image file unnecessarily large. I have tried using the installer_input.txt file to select only the MATLAB product (plus parallel computing toolbox in my case) but when I run my executable I get:
error while loading shared libraries: libmwlaunchermain.so: cannot open shared object file: No such file or directory
I am aware of the other answers fixing this error by setting LD_LIBRARY_PATH. In my case, this is correctly set, but the library file itself is missing, presumably because it is part of one of the products I omitted. I do not get this error when I install MATLAB Runtime with default settings that include every available product.
Which product contains libmwlaunchermain.so? Which are the minimum product(s) I need for MATLAB Runtime to work correctly (in case there are any other missing libraries)?
Answers (4)
Paul Wright
on 24 Mar 2021
3 Comments
Paul Wright
on 24 Mar 2021
Benjamin Tomlinson
on 20 Dec 2022
Thanks for your research Paul - I think it's ridiculous that Matlab don't officially document this functionality as I think many people would find it useful. My Docker image has now been reduced from 10 GB to 2 GB - much more manageable.
Just FYI, I created a python script which takes as inputs (1) the complete MCR and (2) "requiredMCRProducts.txt" and outputs the input file as described in your other question. Within the complete MCR folder "productdata", there is a list of files with productNumber (e.g. 35000) which contain the productName (e.g. Core) which can be used to build the instruction for the input file (e.g product.MATLAB_Runtime___Core true).
Thanks again for your posts/answers
Wolf Blecher
on 8 Mar 2023
Digging deep into the Matlab internals, I found the following piece of code, giving me the information directly from the Command line, so this could be used in a Matlab-Script:
pcmn = matlab.depfun.internal.ProductComponentModuleNavigator;
pcmn.productInfo(35000) % Insert your number here
Stefanie Schwarz
on 19 Sep 2024
Edited: Stefanie Schwarz
on 19 Sep 2024
2 votes
For newer versions of MATLAB, there are supported ways to create selective MATLAB Runtime installers and Docker containers with 'compiler.runtime.customInstaller' and 'compiler.runtime.createDockerImage'.
For more information, see:
Raymond Norris
on 22 Mar 2021
1 vote
Paul see if this will help: https://www.mathworks.com/help/compiler/package-matlab-standalone-applications-into-docker-images.html
3 Comments
Paul Wright
on 22 Mar 2021
Raymond Norris
on 22 Mar 2021
I would expect that the generated docker image will include all MATLAB libraries needed based on the products you need for the code you're running for the MATLAB Runtime.
If you build it on your own, also look at https://github.com/mathworks-ref-arch/container-images (note these are for Ubuntu but ought to get you heading in the right direction) for 3p library dependencies MATLAB has.
Paul Wright
on 22 Mar 2021
Jeff Mandel
on 29 Jan 2025
I have been studying this in my quest for the sub-gigabyte base image. While when I'm writing a report on what my software does, I love the ability to generate plots and such, in my production system all I'm doing is generating json structures that I pass out to my javascript UI. I initialize the runtime with:
System.setProperty("java.awt.headless", "true");
MWApplication.initialize(MWMCROption.NODISPLAY,MWMCROption.NOJVM);
Having set MATLAB_JAVA to the JRE I get from my container base (eclipse-temurin:17-jre-noble). When I run this, MATLAB carps about missing X11 libraries, but my code still runs. All these dependencies are created in these plugins:
- matlab_graphics_ui
- pf_matlab_integ
If I make a copy of my Runtime that I installed following Stefanie's link and delete these 2 directories, poof, no more complaints about missing X11 libraries. Installing something like libgl1 was adding ~300M to my base image. Looking further (using auditctl to see what files are getting pulled in when I exercise every line in my MATLAB code), I see that these two plugins were pulling in another 85M of libraries. I'm still working on this approach, but I have my $MCRRUNTIME directory slimmed way down:
du -hs /usr/local/MATLAB/MATLAB_Runtime/R2024b
2.7G /usr/local/MATLAB/MATLAB_Runtime/R2024b
du -hs mcr2
606M mcr2
This has my Docker image down from the >4G I was getting with the standard approach to ~1G. So here is my suggestion. In the options for product numbers, have a version (say 35001) Headless Core that drops all the stuff that you don't need when you initialize with MWMCROption.NODISPLAY. Conversely, some % flags like %noX11, %nocups, %nosound would be nice. Part of this is getting a smaller Docker image, but another aspect of this is reducing the number of libraries that have CVE warnings when my image gets scanned.
Categories
Find more on Containers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!