• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

mathworks-ref-arch/matlab-dockerfile: Create a docker container that contains a ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

mathworks-ref-arch/matlab-dockerfile

开源软件地址(OpenSource Url):

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

开源编程语言(OpenSource Language):

Dockerfile 100.0%

开源软件介绍(OpenSource Introduction):

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.

Requirements

Build Instructions

Get Sources

# Clone this repository to your machine
git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git

# Navigate to the downloaded folder
cd matlab-dockerfile

Build & Run Docker Image

# Build container with a name and tag of your choice.
docker build -t matlab:r2022a .

# Run the container.
docker run --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab:r2022a -batch "disp('Hello World!')"

For more information on running, see the section on Run the Container.

The Dockerfile defaults to building a container for MATLAB R2022a.

Customize the Image

Customize Products to Install Using MATLAB Package Manager (mpm)

The Dockerfile defaults to installing MATLAB with no additional toolboxes or products into the /opt/matlab folder.

To customize the build, edit the mpm commands in the Dockerfile's usage. You can choose products, release, and destination folder.

Specify products to install as a space-separated list with the --products flag, and specify an install path with the --destination flag. For more information, see MPM.md.

For example, to build a container with MATLAB and Deep Learning Toolbox installed under the path /tmp/matlab, change the corresponding lines in the Dockerfile as follows:

RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm && \ 
    chmod +x mpm && \
    ./mpm install \
        --release=${MATLAB_RELEASE} \
        --destination=/tmp/matlab \
        --products MATLAB Deep_Learning_Toolbox && \
    rm -f mpm /tmp/mathworks_root.log && \
    ln -s /tmp/matlab/bin/matlab /usr/local/bin/matlab

Customize MATLAB Release and License Server

The Dockerfile supports the following Docker build-time variables:

Argument Name Default value Effect
MATLAB_RELEASE r2022a The MATLAB release you want to install. Must be lower-case, for example: r2019b.
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

# Builds an image for MATLAB R2019b
docker build --build-arg MATLAB_RELEASE=r2019b -t matlab:r2019b .

Build an Image with License Server Information

Including the license server information with the docker build command avoids having to pass it when running the container.

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

# Run the container, without needing to pass license information
docker run matlab:r2022a -batch "disp('Hello World!')"

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:

  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 network.lic file with either the docker build or docker run commands.

With the docker build command, either:

  • Specify the LICENSE_SERVER build-arg.

    # Example
    docker build -t matlab:r2022a --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:r2022a .

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

docker run --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab:r2022a -batch "disp('Hello World!')"

Run the Container

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

# Launch MATLAB, print Hello World!, and exit:
docker run --rm -e MLM_LICENSE_FILE=27000@MyServerName matlab:r2022a -batch "disp('Hello World!')"

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 -it --rm matlab:r2022a

Run MATLAB in Batch Mode

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

# Container runs the command RAND in MATLAB and exits.
docker run --rm matlab:r2022a -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 -it --rm matlab:r2022a -logfile "logfilename.log"

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

More MATLAB Docker Resources

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-2022 The MathWorks, Inc. All rights reserved.





鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap