You must perform these steps on a Linux platform. Before starting, you must install the following on the client platform
- Docker
- Git
The following steps guide you through the process of creating a Docker container image that contains a Linux environment with a MATLAB installation. Use the container image as a scalable and reproducible method to deploy MATLAB in a variety of situations including clouds and clusters.
-
Clone this repository to your Linux client using
git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git -
Inside the cloned repository, create a subdirectory named
matlab-install
To install MATLAB into the container image, choose a MATLAB installation method. You can 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-installsubdirectory 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.
- From the MathWorks Downloads page, select the desired version of MATLAB.
- Under the Related Links heading, click the link to get the ISO image for the chosen MATLAB version.
- Download the ISO image for the Linux.
- Extract the ISO into the
matlab-installsubdirectory of the cloned repository.
- 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.
- Make a copy of the file
installer_input.txtin thematlab-installfolder. Move the copy up one directory level, into the root directory of the cloned repository. - Rename the file to
matlab_installer_input.txt. - Open
matlab_installer_input.txtin a text editor and edit the following sections:fileInstallationKeyPaste your File Installation Key and uncomment the line.agreeToLicenseSet the value to yes and uncomment the line.- Specify products to install. Uncomment the line
product.MATLABto install MATLAB. Uncomment the corresponding line for each additional product you want to install. If you are not licensed to use a product, uncommenting the line does not install the product in the container. Your File installation Key identifies the products you can install.
- (Optional) Specify required dependencies in the
Dockerfile. Edit theDockerfileand uncomment the corresponding line for each dependency you want to add. For more information, see Optional Dependencies.
Use the docker build command to build the image, using . to specify this folder. Run the command from the root directory of the cloned repository. Use a command of the form:
docker build . -t matlab:r2019b --build-arg MATLAB_RELEASE=R2019b --build-arg LICENSE_SERVER=27000@MyServerName
You must supply a tag for the image using the -t option, for example, matlab:2019b. The tag names the repository for later use and deployment.
Specify the location of the network licence manager using --build-arg LICENSE_SERVER=27000@MyServerName. Replace 27000@MyServerName with the port and location of your license manager. Alternatively, you can use a license.dat or network.lic file to provide the location of the license manager. For more information, see Use a License File to Build Image.
You must specify the MATLAB release using --build-arg MATLAB_RELEASE=R20xxx, where R20xxx refers to a MATLAB release you are trying to build.
Use the docker run command to run the container. Run the command from the root directory of the cloned repository. Use a command of the form:
docker run -it --rm matlab:r2019b
-itoption runs the container interactively.--rmoption automatically removes the container on exit. Any extra arguments after the container tag are passed directly to MATLAB. For example, the following command printshello worldin MATLAB and then exits MATLAB.
docker run -it --rm matlab:r2019b -r "disp('hello world');exit"
For some workflows and toolboxes, you must specify dependencies. You must do this if you want to do any of the following tasks.
- Install extended localization support for MATLAB
- Play media files from MATLAB
- Run a network license manager inside the container
- Generate code from Simulink
- Use mex functions with gcc, g++, or gfortran
- Use the MATLAB Engine API for C and Fortran
- Use the Polyspace 32-bit tcc compiler
Edit the Dockerfile and uncomment the relevant lines to install the dependencies.
If you have a license.dat file from your license administrator, you can use this file to provide the location of the license manager for the container image.
- Open the
license.datfile. Copy theSERVERline 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.licin the root directory of the cloned repository. - Open the
Dockerfile, and comment the lineENV MLM_LICENSE_FILE - Uncomment the line
ADD network.lic /usr/local/MATLAB/$MATLAB_RELEASE/licenses/ - Run the docker build command without the
--build-arg LICENSE_SERVER=27000@MyServerNameoption. Use a command of the form
docker build . -t matlab:r2019b --build-arg MATLAB_RELEASE=R2019b
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?