Borrar filtros
Borrar filtros

Including a Toolbox When Creating a Standalone Application & Packaging it Into a Matlab Runtime Docker Image

49 visualizaciones (últimos 30 días)
I'm attempting to convert a set of scripts I have into its own standalone binary executable, and then have that runnable in a container after it's copied over to a docker image with a Matlab runtime capable of running it.
I've successfully replicated all of the steps listed on that help page with the magic square example - on the host, the binary runs just fine as a standalone executable, and also runs just fine in a container when packed up into the image that the Docker compiler automatically pulls in the
compiler.package.docker
call (on 2021a, it pulls matlabruntime/r2021a/release/update0/4000000000000000 as the base image of the runtime).
The problem is when I try to build a standalone that relies on a toolbox. I can't seem to find any option to include a toolbox dependancy, even in the form of a .mltbx. The toolbox in question is specifically the "Database Toolbox Interface for Apache Cassandra Database", which is not a common toolbox like the Image Processing or DSP toolboxes that I know the runtime images support out of the box, and is one I had to install manually from the Add-ons hub.
When installed, the only source that the plugin writes is a "cassandra.m" to the addon's installation path. I tried to include this as an additional file when building the standalone binary by copying it over to the project directory and running the following:
appfile = fullfile('myMain.m');
res = compiler.build.standaloneApplication(appfile, 'AdditionalFiles', ["./myHelper1.m", "./myHelper2.m", "./cassandra.m"]);
This builds the standalone on the host just fine, and when running said standalone binary on the host machine, it runs perfectly, just like had i ran it from myMain.m in Matlab. The problem is, this does not run on the image that is build from compiler.package.docker. My assumption is when installing the toolbox through the addon GUI on my host machine, additional libraries, as well as some linking, that cassandra.m relies on were installed; libraries that are not included in the runtime image that is pulled by the Matlab docker compiler. This is evidenced by complaining about a slew of missing objects, along the lines as follows:
error while loading shared libraries: libmwmclmcrrt.so.9.10: cannot open shared object file: No such file or directory
These are objects that exist nowhere in the container when poking around by just execing a bash shell, but do exist on my host. As a brute force option, I copied over every single matlab library I have on my host under /matlabrootinstall/bin/glnxa64/ to /opt/matlabruntime/v910/bin/glnxa64/ in the running container, verified that this path is indeed on the LD_LIBRARY_PATH in the container, and figured I would sort out the set of objects that was actually needed later. I no longer recieved any complaints about missing .sos, but I still recieved errors originating from the objects I copied over from the host into the container when I tried to run the standalone:
Error: Error initializing MATLAB Runtime: Error loading /opt/matlab/R2021a/bin/glnxa64/matlabconnector/serviceprocess/matlabconnector/serviceprocess/services_mode/prod/libmwserviceprocessprod.so.
/opt/matlab/R2021a/bin/glnxa64/matlabconnector/serviceprocess/matlabconnector/serviceprocess/services_mode/prod/libmwserviceprocessprod.so:
undefined symbol: _ZTIN15matlabconnector14serviceprocess6errors13FailedToStartE: Success: Success: Success
This leads me to believe that installing the Cassandra Toolbox through the Addons hub did more than just provide cassandra.m and install some required libraries, as the container has everything that that host has, where the program runs fine, but is failing to execute in the container. Additionally, I tried using the larger base runtime image by running
docker pull mathworks/matlab:r20XYz
directly on the CLI first, then changing the FROM line in the generated Dockerfile from the Docker Compiler to use this image instead of the one that was automaticlly populated with, but I run into the same exact problems listed above of missing objects, and then a non-functioning object of libmwserviceprocessprod.so once I do copy over everything from the host.
With the above evidence, I've concluded I need to somehow replicate the process of having installed the Cassandra Database Toolbox as if I went through the Addons Hubs, except inside of a Matlab Runtime Container created from the Matlab Docker Compiler or include the toolbox, in the form of a .mltbx or otherwise, as a dependancy when building the standalone binary. How would I go about doing this, or is there a simpler solution and I'm missing the forest for the trees?
TL:DR - how do I include or install a toolbox inside of the Matlab Runtime Environment with Matlab 2021a?
Thanks in advance,
-Matt

Respuestas (1)

Malay Agarwal
Malay Agarwal el 15 de Feb. de 2024
Editada: Malay Agarwal el 15 de Feb. de 2024
Hi Matt,
I understand that you’re trying to containerize MATLAB with additional support packages, specifically the support package “Database Toolbox Interface for Apache Cassandra”.
Please note that as of MATLAB R2021a, the “Database Toolbox provides direct support for Apache Cassandra through the Apache Cassandra Database C++ Interface, and the support package “Database Toolbox Interface for Apache Cassandra” has been discontinued. Installing the “Database Toolbox” should be sufficient to work with Cassandra. Using the toolbox for Cassandra is detailed here: https://www.mathworks.com/help/database/columnar-database.html.
The answer links to a GitHub repository with a Dockerfile. Please follow the following steps in a terminal window:
  • Clone the repository and navigate to the appropriate subfolder:
git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git
cd matlab-dockerfile/alternates/building-on-matlab-docker-image
  • Use the command below to build the docker image with Database Toolbox:
docker build --build-arg MATLAB_RELEASE=r2021a --build-arg ADDITIONAL_PRODUCTS="Database_Toolbox" -t matlab_cassandra:r2021a .
  • The “ADDITIONAL_PRODUCTS” build argument is used to specify the toolboxes that should be added to the container. It’s a space-separated list of toolboxes and spaces in the names of the toolboxes should be replaced by underscores.
  • After the build completes, there should be a docker image with the tag matlab_cassandra:r2021a. To launch MATLAB from this container, use the command:
docker run -it --rm --shm-size=512M matlab_cassandra:r2021a
  • This will launch MATLAB in an interactive command prompt inside the same terminal session. To confirm that the toolbox has been installed, use the “ver” command. The output should look something like this:
There are various other ways of launching MATLAB from the container (for example, in a browser), which are detailed here: https://hub.docker.com/r/mathworks/matlab#:~:text=for%20Docker.-,How%20to%20use%20this%20image,-This%20section%20describes.
Hope this helps!

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by