The Dockerfile in this subfolder shows you how to build and customize a Docker® container for MATLAB® and its toolboxes, using the MATLAB Package Manager (mpm
), and MATLAB Batch Licensing (via matlab-batch). Use this Dockerfile if you have a MATLAB batch licensing token to license MATLAB in your container.
The MATLAB batch licensing project is still in the pilot phase. To inquire about eligibility requirements, fill out this form on the MathWorks® website: Batch Licensing Pilot Eligibility.
You can use this container image as a scalable and reproducible method to deploy and test your MATLAB code in non-interactive environments.
- MATLAB Batch Licensing Token. For more information, see Use MATLAB Batch Licensing.
- Docker.
Access this 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/non-interactive
Build a container with a name and tag.
docker build -t matlab-non-interactive:R2024b .
You can then run the container and use the matlab-batch
command. Test the container by running an example MATLAB command, such as rand
.
docker run --init --rm matlab-non-interactive:R2024b matlab-batch -licenseToken "[email protected]|encodedToken" "rand"
For more information, see Run the Container.
By default, the Dockerfile installs the latest available MATLAB release without any additional toolboxes or products, as well as the latest version of matlab-batch.
Use the options below to customize your build.
The Dockerfile supports these Docker build-time variables:
Argument Name | Default Value | Description |
---|---|---|
MATLAB_RELEASE | R2024b | MATLAB release to install, for example, R2023b . |
MATLAB_PRODUCT_LIST | MATLAB | Space-separated list of products to install. For more information, see MPM.md. For example: MATLAB Simulink Deep_Learning_Toolbox Fixed-Point_Designer |
MATLAB_INSTALL_LOCATION | /opt/matlab/R2024b | Path to install MATLAB. |
Use these arguments with the docker build
command to customize your image.
Alternatively, the default values for these arguments can be changed directly in the Dockerfile.
For example, to build an image for MATLAB R2021b, use this command.
docker build --build-arg MATLAB_RELEASE=R2021b -t matlab-non-interactive:R2021b .
For supported releases, see MATLAB Batch Licensing support.
For example, to build an image with MATLAB and the Statistics and Machine Learning Toolbox™, use this command.
docker build --build-arg MATLAB_PRODUCT_LIST="MATLAB Statistics_and_Machine_Learning_Toolbox" -t matlab-stats-non-interactive:R2024b .
For example, to build an image with MATLAB installed at /opt/matlab
, use this command.
docker build --build-arg MATLAB_INSTALL_LOCATION="/opt/matlab" -t matlab-non-interactive:R2024b .
This container requires a MATLAB Batch Licensing Token to license MATLAB in non-interactive (batch) workflows. matlab-batch licenses all the products contained in the token before running your statement.
Provide the MATLAB Batch Licensing token when calling matlab-batch
.
With the docker run
command, use one of these options.
-
Specify the
-licenseToken
run-arg.# Example docker run --init --rm matlab-non-interactive:R2024b matlab-batch -licenseToken "[email protected]|encodedToken" "disp('Hello, World.')"
-
Specify the
MLM_LICENSE_TOKEN
environment variable.# Example export MLM_LICENSE_TOKEN="[email protected]|encodedToken" docker run --init --rm -e MLM_LICENSE_TOKEN matlab-non-interactive:R2024b matlab-batch "disp('Hello, World.')"
This Dockerfile's default entry-point is a shell session. After you start the container, use matlab-batch
to start MATLAB with a MATLAB batch licensing token.
# Launch MATLAB, print Hello, World., and exit:
docker run --init --rm matlab-non-interactive:R2024b matlab-batch -licenseToken "[email protected]|encodedToken" "disp('Hello, World.')"
You can set your MATLAB batch licensing token at the container level by setting the MLM_LICENSE_TOKEN
environment variable, as shown in the examples below.
To start the container, run a MATLAB command and exit, use this command.
# Container runs the command RAND in MATLAB and exits.
export MLM_LICENSE_TOKEN="[email protected]|encodedToken"
docker run --init --rm -e MLM_LICENSE_TOKEN matlab-non-interactive:R2024b matlab-batch rand
To start the container, run a MATLAB script and exit, use this command.
# Container runs the script myscript.m in MATLAB and exits.
export MLM_LICENSE_TOKEN="[email protected]|encodedToken"
docker run --init --rm -v $(pwd):/content -w /content -e MLM_LICENSE_TOKEN matlab-non-interactive:R2024b matlab-batch "myscript"
For more resources, see More MATLAB Docker Resources.
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 in the Dockerfile.
ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=MATLAB:BATCHLICENSING:DOCKERFILE:V1
To learn more, see the documentation: Help Make MATLAB Even Better - Frequently Asked Questions.
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 2024 The MathWorks, Inc.