Unrecognized function or variable when using `str2func` in Docker container

Hello. Inside a Docker container, I am attempting to run .m matlab files that are remotely pulled from a git repository so that a remote code can be changed continously without needed redeployment of a containerized instance of Matlab Production Server. Since addpath is not supported by the Matlab runtime, I created the following function to the run the pulled fnuctions that cannot be added the the path:
function [varargout] = evaluate_function_out_of_path(function_name, function_file_path, options)
arguments
function_name string
function_file_path string
options.function_inputs cell = {}
end
function_handle = str2func(function_name);
current_directory = cd;
cd(function_file_path);
[varargout{1:nargout}] = function_handle(options.function_inputs{:});
cd(current_directory);
end
While I am able to run evaluate_function_out_of_path locally without issue on pulled code not added to the search path, I am receving the following error when ran on a deployed Docker container:
Unrecognized function or variable 'my_function'
The code that I am pulling is not compiled. What I am worried about is that the pulled source code must be compiled first before it can be used during runtime. Is this assumption right? Oddly enough, I am able to run built in functions with str2func inside the container without any kind of compilation such as:
str2func("@() disp('hello world')")
Let me know if you need clarification; I'll edit the question accordingly. Thanks in advance!

8 commentaires

Bruno Luong
Bruno Luong le 10 Avr 2024
Modifié(e) : Bruno Luong le 10 Avr 2024
I don't think you can run anyting that is NOT compiled in the same session than he main function. All the mfile are crypted and signed and the Runtime will not consider any outsider, formost for security reason.
Chandler
Chandler le 10 Avr 2024
Modifié(e) : Chandler le 10 Avr 2024
I see. What I don't understand is the fact that I can run uncomplied string function (e.g. str2func("@() disp('hello world')")) from the container using str2func.
Instead of
fh = str2fun(fname)
% ...
fh(arg{:});
You can try without str2fun and directly call
feval(fname, arg{:})
My bet is that the issue still exist and it will refuse to run.
Chandler
Chandler le 11 Avr 2024
Modifié(e) : Chandler le 11 Avr 2024
Hello Bruno. feval produces the same error. Thanks for the input nonetheless
Prabhakar
Prabhakar le 11 Avr 2024
Modifié(e) : Prabhakar le 11 Avr 2024
I'm not sure that the Production server product is meant to be used as a general purpose execution runtime to run arbitrary code.
The MATLAB container on dockerhub might be better suited for this purpose.
See https://hub.docker.com/r/mathworks/matlab
Look for the -batch flag in the documentation on the page listed above.
Chandler
Chandler le 11 Avr 2024
Modifié(e) : Chandler le 11 Avr 2024
Thank you Prabhakar. I'll have a look
After fiddling with the Matlab container, I couldn't think of a way to serve an http server to run matlab remotely. While creating and deploying something like a node express server to serve http requests or even port forward the container, building a maltab microservice is the cleanest way so far. Is there no way to run ephemeral matlab code in Matlab Production Server?
Hi Chandler,
I'm the product manager for MATLAB Production Server and I'd be interested in hearing more about your use case for uncompiled code behind MATLAB Production Server, but I also wanted to address something I noticed in your OP:
You shouldn't need to redeploy your MATLAB Production Server container when you make changes to your deployed code. Provided you've packaged an updated deployable archive (CTF file) you should be able to map a volume into the container and replace the existing deployable archive in that volume without redeploying (or even restarting) the container itself.
Cheers,
Nicole

Connectez-vous pour commenter.

Réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by