Unable to use Simulink when running inside docker

11 ビュー (過去 30 日間)
João Henrique
João Henrique 2025 年 6 月 15 日
回答済み: Jacob Mathew 2025 年 6 月 16 日
Hello. I've recently tried to use Simulink with python through matlab. Due to some errors in linux, I ended up running matlab engine successfully after building with a Docker container by following this tutorial. I then edit the Dockerfile to select R2025a instead of R2023b
After that, I installed simulink inside my Dockerfile
ARG MATLAB_RELEASE=R2025a
# Build MATLAB image
FROM mathworks/matlab:R2025a
# Declare global
ARG MATLAB_RELEASE
# Necessary packages to run python3 properly
USER root
RUN apt-get update && \
apt-get install -y python3.12-dev python3.12-venv
RUN wget -O /mpm https://www.mathworks.com/mpm/glnxa64/mpm
RUN chmod +x /mpm
RUN /mpm install --release=$MATLAB_RELEASE --destination=/opt/matlab Simulink 'Control System Toolbox'
USER matlab
RUN python3.12 -m pip install numpy --break-system-packages
# Install MATLAB Engine API for Python
RUN /bin/sh -c 'cd /opt/matlab/$MATLAB_RELEASE/extern/engines/python && sudo python3 setup.py install'
Where small_test.m file is the following:
function [] = small_test()
si = Simulink.SimulationInput("smith_water_cr")
end
This give me the following error inside matlab shell:
>> small_test
Simulink.SimulationInput requires Simulink.
Error in small_test (line 2)
si = Simulink.SimulationInput("smith_water_cr");
Using load_system also gives me the same error:
function [] = small_test()
load_system('simulink')
end
Then:
>> small_test
load_system requires one of the following:
RF Toolbox
Simulink
Also some notes, here is my file structure:
small_test.m
smith_water_cr.slx
also please notice that I can run just fine if I use directly inside the shell:
matlab@f6fd79e935a8:~/Documents/MATLAB$ matlab
% ...
>> si = Simulink.SimulationInput("smith_water_cr")
si =
SimulationInput with properties:
ModelName: "smith_water_cr"
% etc

回答 (1 件)

Jacob Mathew
Jacob Mathew 2025 年 6 月 16 日
Hey ,
MathWorks has a dedicated GitHub page on MATLAB Docker Images and creating custom docker images based on the version, products and support packages you need. This would be the ideal starting point:
Spedifically, you can set the MATLAB_PRODUCT_LIST variable in the dockerfile to the list of addtional products or support packages you need. In the above code you have mentioned Simulink and Control System Toolbox. You can set that as follows:
ARG MATLAB_PRODUCT_LIST="MATLAB Simulink Control_System_Toolbox"
You can customise the dockerfile as mentioned above and add the necessary command to install Python and Python engine for MATLAB as mentioned in the MATLAB Answers Post you referenced. Additionally, the sample dockerfile in the GitHub repository also installs the necessary dependencies needed for MATLAB Package Manager (mpm) to run without hiccups.

カテゴリ

Help Center および File ExchangeDevelopment Computer Setup についてさらに検索

製品


リリース

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by