Install Updates, Toolboxes, Support Packages, and Add-Ons in Containers
To install toolboxes in a programmatic way in a MATLAB® container image, you can customize the MATLAB Docker Hub container image by using MATLAB Package Manager. For more information, see Building on MATLAB Docker Image.
You can also install the latest MATLAB updates or install additional toolboxes, support packages, and add-ons in an interactive manner in a MATLAB container that you obtain from Docker® Hub. You can then save the container to a new container image avoid having to reinstall your changes.
This example shows how to make changes interactively in MATLAB R2022b in a container and save the container to a new container image for later use.
Pull MATLAB Container Image
Download the MATLAB container image onto the host machine by running this command at the command line:
docker pull mathworks/matlab:r2022b
To download the container image for a different release, replace the
r2022b tag with the desired MATLAB release, for example,
r2022a. Downloading and
extracting the container image can take a few minutes.
Run Container Session Using Virtual Network Computing (VNC)
To install toolboxes or update MATLAB, you must run the MATLAB container in VNC mode by entering this command in the terminal:
docker run --init -it --rm -p 5901:5901 -p 6080:6080 --shm-size=512M mathworks/matlab:r2022b -vnc
-p hostport:containerport maps ports from the
Docker host instance to ports inside the container so that you can connect to
the container desktop. The container uses the ports
5901 for VNC
6080 for web browser connection. If you are
deploying multiple containers on the same host instance, you must increment the host
ports until you find a free port. For example:
-p 5902:5901 -p 6081:6080
To connect to the desktop where you can open MATLAB:
Use a VNC client to connect to display 1 of the Docker host machine (
If you do not have a VNC client, point a browser to port 6080 of the Docker host machine running this container (
If your container is not running on your local machine, replace
localhost with the fully qualified domain name (FQDN) of the
computer on which the container is running.
The default VNC password is
Install Updates, Toolboxes, Support Packages, and Add-Ons
To install toolboxes or update MATLAB, you must run MATLAB with superuser privileges. At a terminal inside the container session, start MATLAB with root privileges using this command.
You can install updates and toolboxes from within MATLAB.
To install updates, see Update an Existing Installation (MATLAB).
To install toolboxes, support packages, and add-ons, go to the Home tab and, in the Environment section, click the Add-Ons icon. For example, to add Simulink® to your MATLAB container, go to the Add-On Explorer and install Simulink. For more information about how to install toolboxes and add-ons, see Get and Manage Add-Ons (MATLAB).
After you install the updates and additional products, MATLAB restarts. To verify
the updates and installation of additional toolboxes and add-ons, enter
ver in the MATLAB Command Window.
After you install the desired updates and toolboxes, save the container to a new
container image for later use to avoid having to reinstall your changes. Because the
--rm flag removes the container when you close it, do not
close the container.
Open a new command window on your host machine. Find the container ID of the running container by listing the information related to all running containers.
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3d555451f07a nvcr.io/partners/matlab:r2020a "/bin/run.sh" 24 minutes ago Up 24 minutes 0.0.0.0:5901->5901/tcp, 0.0.0.0:6080->6080/tcp relaxed_pasteur
docker commit with the
--change flag to
create a snapshot. You can use this snapshot to open the saved container using
different modes next
docker commit --change 'ENTRYPOINT ["/bin/run.sh"]' <container ID> matlabwithtoolboxes:r2022b
This command saves the container to a new container image with the name
matlabwithtoolboxes:r2022b on the Linux® operating system. For other operating systems, use the appropriate
quotes. For more information see, Save Changes in Containers.
To save the container with the VNC option as well, omit the
--change flag. This allows you to run the saved container
using the VNC mode by default the next time.
docker commit <container ID> matlabwithtoolboxes:r2022b