Main Content

Create a Custom MATLAB Container

Access MATLAB® on the cloud or in server environments by using a MATLAB container image that you can create from a Dockerfile. Use this solution when you want to create a Docker® container image with a custom MATLAB installation in a Linux® environment.

Alternatively, for an out-of-the-box MATLAB container image that you can pull from Docker Hub directly, see MATLAB Container on Docker Hub.

Requirements

To create and use a custom MATLAB container, you need:

  • A host machine with Docker and Git™ installed.

  • A MATLAB license administered via a network license manager that meets the following conditions:

  • To license MATLAB in the container, you must supply the port number and DNS address of the network license manager. You can add this information either when you build the container image or when you start the container.

    • To set this information when you build the container image, add an option of the following form to the docker build command:

      --build-arg LICENSE_SERVER=27000@MyLicenseServer

      Alternatively, you can use a license file to provide the location of the license manager when you build the container image. If you want to use a Network Named license type with the container image, you must first add the user name in the Dockerfile before running the docker build command. After building the container image, run the container with the specific user name associated with the license. For more information, see Use a Network Named License in a Container.

    • To set this information when you run the container image, add an option of the following form to the docker run command:

      -e MLM_LICENSE_FILE=27000@MyLicenseServer

Use a Network Named License in a Container

If you are using a Network Named license with the container, you must run the container with the specific user name associated with the license. Users cannot be added to containers after the container image is built, so be sure to build any user name you will potentially need to use into the Dockerfile before you build the container image.

To define users for the container, add users in the Dockerfile and then run the container as a specified user. The following Dockerfile command adds the specified user to the container:

RUN useradd -ms /bin/bash <USERNAME>

This next Dockerfile command sets the container to run as the specified user:

USER <USERNAME>

The -u runtime flag overrides any USER command that was built into the container. You can use this to change the user of the container at runtime. For more information, see the Docker documentation.

Create Container

To create a Docker container image with a custom MATLAB installation using a Dockerfile, follow the instructions in this GitHub® repository:

For other possibilities, see the examples in the alternates folder of this GitHub repository:

Related Topics

External Websites