Install Updates, Toolboxes, Support Packages, and Add-Ons in Containers
You can install updates, toolboxes, support packages, and add-ons in containers either programmatically using the command line or interactively using a Virtual Network Computing (VNC) Client.
Install Programmatically
To install toolboxes and support packages in a MATLAB® container image in a programmatic way using the command line, see the instructions in this GitHub® repository: Building on MATLAB Docker Image. This repository allows you to build a container image on top of the MATLAB Docker Hub container image using MATLAB Package Manager.
The repository contains a Dockerfile that you can use with the Docker® build command to create a container image. You can pass arguments during the Docker build process to specify which products to install, set the MATLAB release, and configure a network license manager. Alternatively, you can manually customize the Dockerfile in the repository and then build the container image.
Video Walkthrough
This video shows you how to build a Docker container with MATLAB and its toolboxes using the Dockerfile in the repository by passing the arguments during the Docker build process.
Install Interactively
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 to avoid having to reinstall your changes.
This example shows how to make changes interactively in MATLAB R2023b 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:r2023b
To download the container image for a different release, replace the
r2023b
tag with the desired MATLAB release, for example, r2023a
. Downloading and extracting
the container image can take a few minutes.
Run Container Session in VNC Mode
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:r2023b -vnc
The option -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 connection
and 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 (
localhost:1
).If you do not have a VNC client, point a browser to port 6080 of the Docker host machine running this container (
http://localhost:6080
).
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 matlab
.
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.
sudo matlab
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.
Save Container
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
3d555451f07a
.Use docker commit
with the --change
flag to
create a snapshot. You can use this snapshot to open the saved container using different
modes next
time.
docker commit --change 'ENTRYPOINT ["/bin/run.sh"]' <container ID> matlabwithtoolboxes:r2023b
This command saves the container to a new container image with the name
matlabwithtoolboxes:r2023b
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:r2023b