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:
Linked to a bat365 Account.
Configured for cloud use. You can identify your license type and administrator by viewing your bat365 Account. Administrators can consult Administer Network Licenses.
You must supply the port number and DNS address of the network license manager when you build the container. Add an option of the following form to the
docker build
command when you create the container:Alternatively, you can use a license file to provide the location of the license manager.--build-arg LICENSE_SERVER=27000@MyLicenseServer
If you want to use a Network Named license type with the container, you must first add the user name in the Dockerfile and then run the container with the specific user name associated with the license. For more information, see Use a Network Named License in a Container.
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 is built, so be sure to build any user name you will potentially need to use into the Dockerfile before you build the container.
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:
matlab-installer
is an example of a Dockerfile that uses the MATLAB installer rather than MATLAB Package Manager (mpm) to install MATLAB in the container, and allows you to install some toolboxes that are not currently supported by MATLAB Package Manager.building-on-matlab-docker-image
is an example of a Dockerfile that builds on top of the MATLAB Container Image on Docker Hub to install extra toolboxes.