• Stars
    star
    321
  • Rank 130,752 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created about 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create a docker container that contains a MATLAB install

Create a MATLAB Container Image

This repository shows you how to build and customize a Docker® container for MATLAB® and its toolboxes, using the MATLAB Package Manager (mpm).

You can use this container image as a scalable and reproducible method to deploy and test your MATLAB code.

You can also download prebuilt images based on this Dockerfile from here.

Requirements

Build Instructions

Get Sources

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

git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git
cd matlab-dockerfile

Build & Run Docker Image

Build container with a name and tag of your choice.

docker build -t matlab:r2023a .

Run the container. Test the container by running an example MATLAB command such as ver.

docker run --init --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab:r2023a -batch ver

The Dockerfile defaults to building a container for MATLAB R2023a.

The example command ver displays the version number of MATLAB and other installed products. For more information, see ver. For more information on running the container, see the section on Running the Container.

Note

Using the --init flag in the docker run command ensures that the container stops gracefully when a docker stop or docker kill command is issued. For more information, see the following links:

Customize the Image

By default, the Dockerfile installs MATLAB for the latest available MATLAB release without any additional toolboxes or products in the /opt/matlab/${MATLAB_RELEASE} folder.

Use the options below to customize your build.

Customize MATLAB Release, MATLAB Product List, MATLAB Install Location and License Server

The Dockerfile supports the following Docker build-time variables:

Argument Name Default value Description
MATLAB_RELEASE r2023a The MATLAB release you want to install, in lower-case. For example: r2019b
MATLAB_PRODUCT_LIST MATLAB Products to install as a space-separated list. For more information, see MPM.md. For example: MATLAB Simulink Deep_Learning_Toolbox Fixed-Point_Designer
MATLAB_INSTALL_LOCATION /opt/matlab/r2023a The path to install MATLAB.
LICENSE_SERVER unset The port and hostname of the machine that is running the Network License Manager, using the port@hostname syntax. For example: 27000@MyServerName

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

Build an Image for a Different Release of MATLAB

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

docker build --build-arg MATLAB_RELEASE=r2019b -t matlab:r2019b .

Build an Image with a specific set of products

For example, to build an image with MATLAB and Simulink, use this command.

docker build --build-arg MATLAB_PRODUCT_LIST='MATLAB Simulink' -t matlab:r2023a .

Build an Image with MATLAB installed to a specific location

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:r2023a .

Build an Image with License Server Information

Including the license server information with the docker build command means you do not have to pass it when running the container.

# Build container with the License Server.
docker build --build-arg LICENSE_SERVER=27000@MyServerName -t matlab:r2023a .

# Run the container, without needing to pass license information.
docker run --init --rm matlab:r2023a -batch ver

Use the Network License Manager

This container requires a Network License Manager to license and run MATLAB. You will need either the port and hostname of the Network License Manager, or a network.lic file.

Step 1: Contact your system administrator, who can provide one of the following:

  1. The address to your server, and the port it is running on. For example: [email protected]

  2. A network.lic file which contains the following lines:

    # Sample network.lic
    SERVER MyServerName.example.com <optional-mac-address> 27000
    USE_SERVER
  3. A license.dat file. Open the license.dat file, find the SERVER line, and either extract the port@hostname, or create a network.lic file by copying the SERVER line and adding a USE_SERVER line below it.

    # snippet from sample license.dat
    SERVER MyServerName.example.com <mac-address> 27000

Step 2: Use port@hostname or the network.lic file with either the docker build or the docker run command.

With the docker build command, either:

  • Specify the LICENSE_SERVER build-arg.

    # Example
    docker build -t matlab:r2023a --build-arg LICENSE_SERVER=27000@MyServerName .
  • Use the network.lic file:

    1. Place the network.lic file in the same folder as the Dockerfile.
    2. Uncomment the line COPY network.lic /opt/matlab/licenses/ in the Dockerfile.
    3. Run the docker build command without the LICENSE_SERVER build-arg:
    # Example
    docker build -t matlab:r2023a .

With the docker run command, use the MLM_LICENSE_FILE environment variable. For example:

docker run --init --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab:r2023a -batch ver

Run the Container

If you did not provide the license server information when building the image, then provide it when running the container. Set the environment variable MLM_LICENSE_FILE using the -e flag, with the network license manager's location in the format port@hostname.

# Start MATLAB, print version information, and exit:
docker run --init --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab:r2023a -batch ver

You can run the container without specifying MLM_LICENSE_FILE if you provided the license server information when building the image, as shown in the examples below.

Run MATLAB in an Interactive Command Prompt

To start the container and run MATLAB in an interactive command prompt, execute:

docker run --init -it --rm matlab:r2023a

Run MATLAB in Batch Mode

To start the container, run a MATLAB command, and then exit, execute:

# Container runs the command RAND in MATLAB and exits.
docker run --init --rm matlab:r2023a -batch rand

Run MATLAB with Startup Options

To override the default behavior of the container and run MATLAB with any set of arguments, such as -logfile, execute:

docker run --init -it --rm matlab:r2023a -logfile "logfilename.log"

To learn more, see the documentation: Commonly Used Startup Options.

More MATLAB Docker Resources

  • Explore prebuilt MATLAB Docker Containers on Docker Hub®: https://hub.docker.com/r/mathworks

  • This Dockerfile builds on the matlab-deps container image and installs MATLAB. For other possibilities, see the examples in the alternates folder of this repository:

  • Enable additional capabilities using the MATLAB Dependencies repository. 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.
    • 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.

    The matlab-deps repository repository lists Dockerfiles for various releases and platforms. Click here to view the Dockerfile for R2023a.

    These Dockerfiles contain commented lines with the libraries that support these additional capabilities. Copy and uncomment these lines into your Dockerfile.

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 the following line in the Dockerfile:

ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=MATLAB: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 (c) 2021-2023 The MathWorks, Inc. All rights reserved.


More Repositories

1

matlab-on-aws

Stand up a MATLAB desktop with Remote Desktop access using AWS CloudFormation
HCL
107
star
2

matlab-on-azure

Stand up a MATLAB desktop with Remote Desktop access using Azure Deployment
HCL
36
star
3

container-images

MathWorks container images on Docker Hub
Dockerfile
34
star
4

matlab-parallel-server-on-aws

Stand up a MATLAB Parallel Server cluster using CloudFormation
Shell
27
star
5

matlab-integration-for-jupyter

Create Jupyter Docker images with MATLAB integration
Dockerfile
27
star
6

matlab-production-server-on-aws

Stand up a MATLAB Production Server using CloudFormation
Python
23
star
7

matlab-production-server-on-kubernetes

MATLAB Production Server on Kubernetes
17
star
8

getting-started-with-matlab-in-docker

17
star
9

matlab-apache-kafka

MATLAB Interface for Apache Kafka
MATLAB
16
star
10

matlab-production-server-on-azure

Stand up a MATLAB Production Server using Azure Deployment
Python
12
star
11

mathworks-gcp-support

Complete reference to all Google Cloud Platform (GCP) support packages for use with MathWorks products on the Cloud. This is an umbrella to be able to recursively pull all GCP related content from a single project.
MATLAB
12
star
12

matlab-parallel-server-on-azure

Stand up a MATLAB Parallel Server cluster using Azure Deployment
PowerShell
11
star
13

matlab-avro

MATLAB interface for Apache Avro files.
MATLAB
9
star
14

matlab-parallel-server-with-aws-batch

Stand up a MATLAB Parallel Server AWS Batch configuration using CloudFormation
7
star
15

polyspace-bug-finder-server-dockerfile

Create a docker container that contains a Polyspace Bug Finder Server install
7
star
16

matlab-rabbitmq

MATLAB Interface for RabbitMQ
MATLAB
6
star
17

license-manager-for-matlab-on-aws

Stand up a Network License Manager for MATLAB using CloudFormation
Shell
6
star
18

matlab-azure-services

MATLAB Interface for Azure Services, supports KeyVault, Azure Blob & Azure Data Lake
MATLAB
5
star
19

matlab-aws-common

Code common to MATLAB interfaces. Code in this repository is used as a dependency for other projects such as matlab-aws-s3.
MATLAB
5
star
20

matlab-azure-blob

MATLAB interface for Windows Azure Blob Storage.
MATLAB
4
star
21

matlab-parquet

MATLAB Interface for Apache Parquet
4
star
22

matlab-aws-s3

MATLAB interface for AWS S3.
MATLAB
4
star
23

matlab-aws-athena

MATLAB Interface for AWS Athena
MATLAB
4
star
24

matlab-on-aws-win

PowerShell
3
star
25

license-manager-for-matlab-on-azure

Stand up a Network License Manager for MATLAB using Azure Deployment
PowerShell
3
star
26

matlab-google-cloud-storage

Support for the Google Cloud Platform. This package contains the client Library for Google Cloud Storage
MATLAB
3
star
27

matlab-web-app-server-on-aws

Stand up a MATLAB Web App Server using CloudFormation
Python
3
star
28

matlab-apache-spark

MATLAB
3
star
29

matlab-aws-sns

MATLAB Interface for AWS SNS
MATLAB
3
star
30

mathworks-aws-support

Amazon Web Services (AWS) support packages providing interfaces for use with MathWorks products on the AWS Cloud. This is an umbrella project to be able to recursively pull all AWS related content from a single project.
3
star
31

matlab-on-azure-win

PowerShell
2
star
32

matlab-openapi-generator

MATLAB Generator for OpenAPI enables generation of RESTful Clients and Models based on OpenAPI 3.0 specifications
MATLAB
2
star
33

matlab-parallel-server-on-kubernetes

Utilities for using MATLAB® Parallel Server in a Kubernetes® cluster.
Go
2
star
34

matlab-web-app-server-on-azure

Stand up a MATLAB Web App Server using Azure Deployment
Python
2
star
35

iac-building-blocks

MathWorks Infrastructure as Code Building Blocks
1
star
36

matlab-azure-data-lake

MATLAB Interface for Azure Data Lake.
MATLAB
1
star
37

matlab-aws-dynamodb

MATLAB Interface for AWS DynamoDB
MATLAB
1
star
38

matlab-gcp-common

Common components used across MATLAB® interfaces for Google Cloud Platform™ services
MATLAB
1
star
39

license-manager-for-matlab-on-gcp-using-terraform

Stand up a Network License Manager for MATLAB using Terraform
Shell
1
star
40

polyspace-access-on-aws

Stand up a Polyspace Access server using AWS CloudFormation
1
star
41

matlab-codespaces

This repository show different ways you can configure your dev containers to run MATLAB in codespaces.
Dockerfile
1
star
42

openapi-productionserver

​​OpenAPI Interface for MATLAB Production Server​
MATLAB
1
star