This repository demonstrates how to create a Docker® container image for MATLAB® from local files using the MATLAB installer on a Linux® Operating System. For other operating systems, use the appropriate commands. This method uses the MATLAB installer rather than MATLAB Package Manager (mpm). The MATLAB installer is the default graphical installer for MATLAB. The Dockerfile in this subfolder shows you how to use the MATLAB installer with the -mode silent
flag to install MATLAB without a graphical user interface. Use this Dockerfile if:
- You need toolboxes that mpm cannot install.
- You prefer using the MATLAB installer workflow, for example, if you have already set it up in your CI/CD pipeline.
If not, use the simpler workflow to build a container image using mpm.
Use the container image as a scalable and reproducible method to deploy MATLAB in a variety of situations including clouds and clusters.
- Docker
- Git™
- Clone this repository using the command:
git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git
- Inside the cloned repository, navigate to the
alternates/matlab-installer
folder - Create a subfolder named
matlab-install
To install MATLAB into the container image, choose a MATLAB installation method. You can either use MATLAB installation files or a MATLAB ISO image.
To obtain the installation files, you must be an administrator for the license linked with your MathWorks® account.
- From the MathWorks Downloads page, select the desired version of MATLAB.
- Download the Installer for Linux.
- Follow the steps at Download Products Without Installation.
- Specify the location of the
matlab-install
subfolder of the cloned repository as the path to the download folder. - Select the installation files for the Linux (64-bit) version of MATLAB.
- Select the products you want to install in the container image.
- Confirm your selections and complete the download.
- (For releases after R2020a) The installation files are automatically extracted into a subfolder with a date stamp. Move these up a level using the following command from the
matlab-installer
folder
mv ./matlab-install/<Time Stamp>/* ./matlab-install/
- From the MathWorks Downloads page, select the desired version of MATLAB.
- Next to the text reading "I WANT TO:" click on the dropdown and select "Get ISOs and DMGs".
- Download the Linux ISO image for your desired release of MATLAB.
- Extract the ISO into the
matlab-install
subfolder of the cloned repository. - The permissions are not setup correctly on files extracted from an ISO downloaded from MathWorks. To remedy this, run the following command from the
alternates/matlab-installer
folder in the repository:
chmod -R +x ./matlab-install/
- Log in to your MathWorks account. Select the license you wish to use with the container.
- Select the Install and Activate tab.
- Select the link “Activate to Retrieve License File”.
- Click the download link under the Get License File heading.
- Select the appropriate MATLAB version and click Continue.
- At the prompt “Is the software installed?” select “No” and click Continue.
- Copy the File Installation Key into a safe location.
- Copy the file
installer_input.txt
from thealternates/matlab-installer/matlab-install
folder into thealternates/matlab-installer
folder and rename the file tomatlab_installer_input.txt
. Do this using the following command:
cp ./matlab-install/installer_input.txt ./matlab_installer_input.txt
- Open
matlab_installer_input.txt
in a text editor and edit the following sections:fileInstallationKey
Paste your File Installation Key and uncomment the line.agreeToLicense
Set the value to yes and uncomment the line.- Specify products to install. Uncomment the line
product.MATLAB
to install MATLAB. Uncomment the corresponding line for each additional product you want to install. Ensure you are not licensed to use the products, otherwise uncommenting the line will not install the product in the container. Your File Installation Key identifies the products you can install.
The Dockerfile supports the following Docker build-time variables:
Argument Name | Default value | Effect |
---|---|---|
MATLAB_RELEASE | latest | The MATLAB release to install, for example, R2023b . |
LICENSE_SERVER | unset | The port and hostname of the machine running the Network License Manager, using the port@hostname syntax. For example: 27000@MyServerName |
Use these arguments with the docker build
command to customize your image. Run a command from the alternates/matlab-installer
of the cloned repository of the form:
docker build -t matlab:$RELEASE --build-arg MATLAB_RELEASE=$RELEASE --build-arg LICENSE_SERVER=$PORT@$MLM_SERVER .
Alternatively, you can change the default values for these arguments directly in the Dockerfile.
Note: Use the LICENSE_SERVER build argument to generate a valid network license file only you cannot supply a license file. Omit this argument if one is provided (or no network licensing is required). Modify the commands within the Dockerfile as described within it.
Note: The build process uses approximately 4GB of RAM so ensure that the docker service has sufficient resources.
Run the container using a command of the form:
docker run --init -it --rm matlab:$RELEASE
-it
option runs the container interactively.--rm
option automatically removes the container on exit.
To change the specified license server at runtime, use the MLM_LICENSE_FILE
environment variable using a command of the form:
docker run --init -it --rm --env MLM_LICENSE_FILE=$PORT@$MLM_SERVER matlab:$RELEASE
If you are not using a license server but instead have a license file, mount it at runtime using a command of the form:
docker run --init -it --rm -v <path/to/licensefile>/license.lic:/license.lic --env MLM_LICENSE_FILE=/license.lic matlab:$RELEASE
Insert any extra arguments after the container tag to add as command line arguments to the MATLAB process inside the container. For example, the following command prints the version of MATLAB and any toolboxes installed in the container in -batch
mode.
docker run --init -it --rm matlab:$RELEASE -batch "ver"
If you have a license.dat
file from your license administrator, use this file to provide the location of the license manager for the container image.
- Open the
license.dat
file. Copy theSERVER
line into a new text file. - Beneath it, add
USE_SERVER
. The file should now look something like this:
SERVER Server1 0123abcd0123 12345
USE_SERVER
- Save the new text file as
network.lic
in the root folder of the cloned repository. - Open the
Dockerfile
, and comment the lineENV MLM_LICENSE_FILE
- Uncomment the line
COPY network.lic /tmp/network.lic
- Run the docker build command without the
--build-arg LICENSE_SERVER=$PORT@$MLM_SERVER
option. Use a command of the form
docker build -t matlab:<Release> --build-arg MATLAB_RELEASE=$RELEASE
For more information about license files, see What are the differences between the license.lic, license.dat, network.lic, and license_info.xml license files?
For more information about running MATLAB in a docker container, see the top level README of this repository
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 the following line in the Dockerfile:
ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=MATLAB:MATLAB_INSTALLER:DOCKERFILE:V1
To learn more, see the documentation: Help Make MATLAB Even Better - Frequently Asked Questions.
We encourage you to try this Dockerfile 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.