Skip to content

Latest commit

 

History

History

building-on-matlab-docker-image

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Building on MATLAB Docker Image

The Dockerfile in this subfolder builds on the MATLAB Container Image on Docker Hub by installing MATLAB® toolboxes and support packages using MATLAB Package Manager (mpm).

Use the Dockerfile as an example of how to build a custom image that contains the features of the MATLAB image on Docker® Hub. These features include accessing the dockerized MATLAB through a browser, batch mode, or an interactive command prompt. For details of the features in the image, see MATLAB Container Image on Docker Hub.

Requirements

  • Docker

Build Instructions

Get the Dockerfile

Access the Dockerfile either by directly downloading this repository from GitHub®, or by cloning this repository and then navigating to the appropriate subfolder.

git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git
cd matlab-dockerfile/alternates/building-on-matlab-docker-image

Quick Start

Build a container with a name and tag.

docker build -t matlab_with_add_ons:R2024b .

You can then run the container with the batch option. Test the container by running an example MATLAB command, such as ver, to display the installed toolboxes.

docker run --init --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab_with_add_ons:R2024b -batch ver

You can check the installed support packages using the MATLAB command matlabshared.supportpkg.getInstalled.

You can also run the container with the browser option to access MATLAB in a browser.

docker run --init --rm -it -p 8888:8888 matlab_with_add_ons:R2024b -browser

For more information, see Run the Container.

Customize the Image

Customize Products to Install Using MATLAB Package Manager

This Dockerfile installs any specified products into the MATLAB installation on the MATLAB Docker Hub image.

To customize the build, either pass a list of products into the ADDITIONAL_PRODUCTS argument when building the Docker image, or edit the default value of that argument in the Dockerfile. The ADDITIONAL_PRODUCTS argument must be a space-separated list surrounded by quotation marks. By default, ADDITIONAL_PRODUCTS includes example products, which you can replace. For example, to build an image containing MATLAB and the Deep Learning Toolbox™, use this command.

docker build --build-arg ADDITIONAL_PRODUCTS="Deep_Learning_Toolbox" -t matlab_with_add_ons:R2024b .

For a successful build, include at least one product. mpm automatically installs any toolboxes and support packages required by the products specified in ADDITIONAL_PRODUCTS. For more information, see MATLAB Package Manager.

You can modify the products argument of mpm, but not the destination folder default value, which is set to match the default value of the MATLAB image on Docker Hub. If you modify the default value for the --destination argument, the build might fail.

Docker Build-Time Variables

The Dockerfile supports the Docker build-time variables listed in the table.

Argument Name Default value Effect
MATLAB_RELEASE R2024b MATLAB release to install, for example, R2023b.
ADDITIONAL_PRODUCTS Symbolic_Math_Toolbox Deep_Learning_Toolbox_Model_for_ResNet-50_Network Space-separated list of toolboxes and support packages to install. For more details, see MATLAB Package Manager.
LICENSE_SERVER unset Port and hostname of a machine that is running a Network License Manager, using the port@hostname syntax, for example, 27000@MyServerName. To use this build argument, the corresponding lines must be uncommented in the Dockerfile.

Use these arguments with the docker build command to customize the image. Alternatively, change the default values for these arguments directly in the Dockerfile.

Build an Image for a Different MATLAB Release

For example, to build an image for MATLAB R2022b, use this command.

docker build --build-arg MATLAB_RELEASE=R2022b -t matlab_with_add_ons:R2022b .

To build an image for MATLAB R2022b with Deep Learning Toolbox and Parallel Computing Toolbox™, use this command.

docker build --build-arg MATLAB_RELEASE=R2022b --build-arg ADDITIONAL_PRODUCTS="Deep_Learning_Toolbox Parallel_Computing_Toolbox" -t matlab_with_add_ons:R2022b .

For supported releases see MATLAB Container Image on Docker Hub.

Build an Image with License Server Information

If you include the license server information with the docker build command, you do not need to pass the information while running the container. To use this build argument, uncomment the corresponding lines in the Dockerfile. If the lines are uncommented, $LICENSE_SERVER must be a valid license server or the browser mode will not start successfully.

Build container with the license server.

docker build -t matlab_with_add_ons:R2024b --build-arg LICENSE_SERVER=27000@MyServerName .

Run the container, without needing to pass license information.

docker run --init matlab_with_add_ons:R2024b -batch ver

Run the Container

The Docker container you build using this Dockerfile inherits run options from its base image. See the documentation for the base image, MATLAB Container Image on Docker Hub (hosted on Docker Hub) for instructions on how to use the base image features. The features include interacting with MATLAB using a web browser, batch mode, or an interactive command prompt, as well as how to provide license information when running the container. Run the commands provided in the instructions using the name of the Docker image that you build using this Dockerfile.

More MATLAB Docker Resources

For more resources, see More MATLAB Docker Resources.

Help Make MATLAB Even Better

You can help improve MATLAB by providing user experience information on how you use MathWorks products. Your participation ensures that you are represented and helps us design better products. To opt out of this service, delete this line in the Dockerfile.

ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=$MW_CONTEXT_TAGS,MATLAB:TOOLBOXES:DOCKERFILE:V1

To learn more, see the documentation: Help Make MATLAB Even Better - Frequently Asked Questions.

Feedback

We encourage you to try this repository with your environment and provide feedback. If you encounter a technical issue or have an enhancement request, create an issue here.


Copyright 2023-2024 The MathWorks, Inc.