Docker:Docker容器内非交互式安装matlab(以静默模式安装)

因为组内有需求打包matlab和其他软件,在网上看了很多文章和matlab官网的安装说明、官方问答,总结了一套能在Docker容器内安装matlab的方法,其中很多地方可能不是最省时最简单的,但是这么多文章里我觉得应该算是比较好理解的,因为是安装过程的回忆版(刚安装完十几分钟吧),如果命令当中有拼写错误、还有目录前后的矛盾,希望各位能够理解,最后希望这篇文章能帮到大家。

一、准备安装包和文件 

1.MATLAB安装包 R2022a_Linux.iso

什么版本都行,以这个为例

2.installer_input.txt

这个是静默安装需要读取的文件,里面内容主要有这些,其他的内容我在下面的把官方installer_input.txt含里面的英文说明贴在下面

这是我的installer_input.txt里面的内容:

agreeToLicense=yes
#这里就是告诉安装脚本你同意安装里面的条款
fileinstallationKey=50***-33***-1***9-**9*2
#这里是填写密钥
destinationFolder=/usr/local/MATLAB/r2022a
#这里告诉安装脚本你想安装在哪里
licensePath=/license.lic
#这里是告诉安装脚本你的许可证文件在哪license.lic,稍后把许可证文件直接复制到docker容器内对应的目录
product.MATLAB
#这里是告诉安装脚本你想安装什么,正常安装matlab有一步不就是选要装哪些工具包你要安装别的就再起一行写
#product.ToolBoxasyourwish

这是官方的文档:

##################################################################
##
## Use this file to specify parameters required by the installer at runtime.
##
## Instructions for using this file.
##
## 1. Create a copy of this template file and fill in the required
##    information.
##
## 2. Uncomment only those lines that start with a single '#'
##    and set the desired values. All allowed values for the
##    parameters are defined in the comments section for each
##    parameter.
##
## 3. Launch the installer from the command line, using the -inputFile option
##    to specify the name of your installer initialization file.
##
##    (Windows) setup.exe -inputFile <file_name>
##    (Linux/macOS) install -inputFile <file_name>
##
##################################################################
##
##
## SPECIFY INSTALLATION FOLDER
## 
## Example:
##        (Windows) destinationFolder=C:\Program Files\MATLAB\RXXXX
##        (Linux) destinationFolder=/usr/local/RXXXX
##        (macOS) destinationFolder=/Applications
##
## Set the desired value for destinationFolder and
## uncomment the line.

# destinationFolder=

##
## SPECIFY FILE INSTALLATION KEY
##
## Example: fileInstallationKey=xxxxx-xxxxx-xxxxx-xxxxx.....
##
## Set the desired value for fileInstallationKey and
## uncomment the line.
##

# fileInstallationKey=

##
## ACCEPT LICENSE AGREEMENT
##
## You must agree to the license agreement to install MathWorks products.
## The license agreement can be found in the license_agreement.txt file at the
## root level of the installation DVD.
##
## Example: agreeToLicense=yes
##
## Set agreeToLicense value to yes or no and
## uncomment the line.

# agreeToLicense=

##
## SPECIFY OUTPUT LOG
##
## Specify full path of file into which you want the results of the
## installation to be recorded.
##
## Example:
##            (Windows) outputFile=C:\TEMP\mathworks_<user_name>.log
##            (Linux/macOS) outputFile=/tmp/mathworks_<user_name>.log
##
## Set the desired value for outputFile and
## uncomment the line.

# outputFile=

##
## Enable Login Named User licensing
##
## Set to Yes to enable use of a Login Named User license for all users of this MATLAB installation
## Users must log in to their MathWorks Account when MATLAB starts.
##
## Example: enableLNU=yes
##
## NOTE: This flag is valid in silent installations only.

# enableLNU=yes

##
## IMPROVE MATLAB
##
## Improve MATLAB by sending user experience information to MathWorks.
## Your participation ensures that you are represented and helps us design
## better products. You can opt in or out of this service either during
## installation or by going to MATLAB preferences.
## https://www.mathworks.com/support/faq/user_experience_information_faq.html

improveMATLAB=yes

########## Begin: Options for Network License Types #########
##
## SPECIFY PATH TO LICENSE FILE (Required for network license types only)
##
## This value is required when installing as a Network End-User
## Example:
##            (Windows) licensePath=C:\TEMP\license.dat
##            (Linux) licensePath=/tmp/license.dat
## Set the desired value for licensePath and
## uncomment the line.

# licensePath=

########## End: Options for Network License Types #########


################# Begin - Windows Only Options ################
## 
## CHOOSE TO SET FILE ASSOCIATIONS
## 
## Set to true if you want the installer to associate file types used by MathWorks
## products to this version of MATLAB, or false if you do not want the installer to
## associate MathWorks file types with this version of MATLAB.
##
## Default value is true.
##
## Set setFileAssoc value to true or false and
## uncomment the line.

# setFileAssoc=true

##
## CHOOSE TO CREATE WINDOWS DESKTOP SHORTCUT
##
## Set to true if you would like the installer to create a desktop shortcut icon
## when MATLAB is installed or false if you don't want the shortcut created.
##
## Default value is false.
##
## Set desktopShortcut value to true or false and
## uncomment the line.

# desktopShortcut=false

## CHOOSE TO ADD SHORTCUT TO WINDOWS START MENU
##
## Set to true if you would like the installer to create a Start Menu shortcut
## icon when MATLAB is installed or false if you don't want the shortcut created.
##
## Default value is true.
##
## Set startMenuShortcut value to true or false and
## uncomment the line.

# startMenuShortcut=true

## CREATE a MATLAB Startup Accelerator task
##
## The MATLAB Startup Accelerator installer creates a
## system task to preload MATLAB into the system's cache
## for faster startup.
##
## NOTE: By default, a MATLAB Startup Accelerator task will
## automatically be created.
##
## If you want a MATLAB Startup Accelerator task to be created,
## do not edit this section.
##
## Set createAccelTask value to false if you do not want to
## create an Accelerator task and uncomment the line.

# createAccelTask=true

################ End - Windows Only Options ################

## SPECIFY PRODUCTS YOU WANT TO INSTALL
##
## By default, the installer installs all the products and
## documentation for which you are licensed. Products you are not licensed for
## are not installed, even if they are listed here.
##
## Note:
## 1. To automatically install all your licensed products, do not edit
##    any lines in this section.
## 
## 2. To install a specific product or a subset of products for
##    which you are licensed, uncomment the line for the product(s) you want
##    to install.

#product.5G_Toolbox
#product.AUTOSAR_Blockset
#product.Aerospace_Blockset
#product.Aerospace_Toolbox
#product.Antenna_Toolbox
#product.Audio_Toolbox
#product.Automated_Driving_Toolbox
#product.Bioinformatics_Toolbox
#product.Bluetooth_Toolbox
#product.C2000_Microcontroller_Blockset
#product.Communications_Toolbox
#product.Computer_Vision_Toolbox
#product.Control_System_Toolbox
#product.Curve_Fitting_Toolbox
#product.DDS_Blockset
#product.DO_Qualification_Kit
#product.DSP_HDL_Toolbox
#product.DSP_System_Toolbox
#product.Data_Acquisition_Toolbox
#product.Database_Toolbox
#product.Datafeed_Toolbox
#product.Deep_Learning_HDL_Toolbox
#product.Deep_Learning_Toolbox
#product.Econometrics_Toolbox
#product.Embedded_Coder
#product.Filter_Design_HDL_Coder
#product.Financial_Instruments_Toolbox
#product.Financial_Toolbox
#product.Fixed-Point_Designer
#product.Fuzzy_Logic_Toolbox
#product.GPU_Coder
#product.Global_Optimization_Toolbox
#product.HDL_Coder
#product.HDL_Verifier
#product.IEC_Certification_Kit
#product.Image_Acquisition_Toolbox
#product.Image_Processing_Toolbox
#product.Industrial_Communication_Toolbox
#product.Instrument_Control_Toolbox
#product.LTE_Toolbox
#product.Lidar_Toolbox
#product.MATLAB
#product.MATLAB_Coder
#product.MATLAB_Compiler
#product.MATLAB_Compiler_SDK
#product.MATLAB_Parallel_Server
#product.MATLAB_Production_Server
#product.MATLAB_Report_Generator
#product.MATLAB_Test
#product.MATLAB_Web_App_Server
#product.Mapping_Toolbox
#product.Medical_Imaging_Toolbox
#product.Mixed-Signal_Blockset
#product.Model_Predictive_Control_Toolbox
#product.Model-Based_Calibration_Toolbox
#product.Motor_Control_Blockset
#product.Navigation_Toolbox
#product.Optimization_Toolbox
#product.Parallel_Computing_Toolbox
#product.Partial_Differential_Equation_Toolbox
#product.Phased_Array_System_Toolbox
#product.Polyspace_Bug_Finder
#product.Polyspace_Bug_Finder_Server
#product.Polyspace_Code_Prover
#product.Polyspace_Code_Prover_Server
#product.Powertrain_Blockset
#product.Predictive_Maintenance_Toolbox
#product.RF_Blockset
#product.RF_PCB_Toolbox
#product.RF_Toolbox
#product.ROS_Toolbox
#product.Radar_Toolbox
#product.Reinforcement_Learning_Toolbox
#product.Requirements_Toolbox
#product.Risk_Management_Toolbox
#product.Robotics_System_Toolbox
#product.Robust_Control_Toolbox
#product.Satellite_Communications_Toolbox
#product.Sensor_Fusion_and_Tracking_Toolbox
#product.SerDes_Toolbox
#product.Signal_Integrity_Toolbox
#product.Signal_Processing_Toolbox
#product.SimBiology
#product.SimEvents
#product.Simscape
#product.Simscape_Battery
#product.Simscape_Driveline
#product.Simscape_Electrical
#product.Simscape_Fluids
#product.Simscape_Multibody
#product.Simulink
#product.Simulink_3D_Animation
#product.Simulink_Check
#product.Simulink_Code_Inspector
#product.Simulink_Coder
#product.Simulink_Compiler
#product.Simulink_Control_Design
#product.Simulink_Coverage
#product.Simulink_Design_Optimization
#product.Simulink_Design_Verifier
#product.Simulink_Desktop_Real-Time
#product.Simulink_PLC_Coder
#product.Simulink_Real-Time
#product.Simulink_Report_Generator
#product.Simulink_Test
#product.SoC_Blockset
#product.Spreadsheet_Link
#product.Stateflow
#product.Statistics_and_Machine_Learning_Toolbox
#product.Symbolic_Math_Toolbox
#product.System_Composer
#product.System_Identification_Toolbox
#product.Text_Analytics_Toolbox
#product.UAV_Toolbox
#product.Vehicle_Dynamics_Blockset
#product.Vehicle_Network_Toolbox
#product.Vision_HDL_Toolbox
#product.WLAN_Toolbox
#product.Wavelet_Toolbox
#product.Wireless_HDL_Toolbox
#product.Wireless_Testbench

3.license.lic

4.libmwlmgrimpl.so

这个是破解版需要的替换的文件,安装说明里面都写着呢

二、配置容器

1.启动容器

在terminal1

docker run -it --privileged=true --name whateveruwant ubuntu:22.04 /bin/bash

--privileged=true是要以root权限启动容器,这样很多操作就可以进行了

2.提前把放准备的安装包和文件的文件夹新建出来

mkdir /matlab
#我是打算在这地方放解压的iso文件
mkdir /things
#我在这个文件夹里放installer_input.txt和libmwlmgrimpl.so
#而我就把license.lic放在根目录下,因为我写的installer_input.txt里面
#写的licensePath=/license.lic,这里要统一

3.将准备的安装包和文件放入容器

在terminal2(在另一个终端运行下面的命令,就可以在不退出容器的前提下将文件转移进容器,或在你会挂载也行,我这样比较好理解)

docker cp /absolutepath/install_input.txt containername:/things
docker cp /absolutepath/license.lic containername:/
docker cp /absolutepath/libmwlmgrimpl.so containername:/things
docker cp /absolutepath/R2022a_Linux.iso containername:/things
#就是把之前写的文件、许可证文件、iso安装包等复制到你想放的文件夹里面
#我这里就是把许可证文件放在根目录下,其他放在/things里面一是方便找,二是方便安装完成后删除

三、安装matlab

1.安装7zip解压iso文件

apt-get update
apt-get install -y p7zip-full
#在ubuntu容器当中需要先更新apt-get之后才能找到软件包

2.解压R2022a_Linux.iso

7z x R2022a_Linux.iso -o/matlab
#把iso文件解压到你想解压的文件夹,例子中我放到了根目录下的matlab文件夹中

3.将解压文件里面的自带的installer_input.txt替换掉

cd /matlab
rm -r installer_input.txt
cp /things/installer_input.txt /matlab

4.给解压得到的文件可执行的权限以及安装位置权限

cd /matlab
chmod a+x -R ./*
chmod a+x -R /usr/local/MATLAB/r2022a/

5.以静默的方式安装matlab

cd /matlab
./install -inputFile ./installer_input.txt

你就等着吧

6.过软件验证(正版不用这步)

cd /usr/local/MATLAB/r2022a/bin/glnxa64/matlab_startup_plugins/lmgrimpl
rm -r libmwlmgrimpl.so
cp /things/libmwlmgrimpl.so ./

6.运行matlab

cd /usr/local/MATLAB/r2022a/bin
./matlab -nodisplay
#以非图像方式运行matlab,我试了一下好像不加这个参数也行

我这里报错了,libXt.so.6: cannot open shared object file: No such file or directory大概这么个错误

我是安装了这两个库(libxtst6、libxt6)解决了

apt-get install -y libxtst6 libxt6

之后就能正常运行了。

然后你也能通过docker commit把这个容器打包成image

如果以Dockerfile的方式创建,我现在正在尝试,可能会再写另一篇文章

要在Docker安装MATLAB,首先你需要理解Docker的基本概念以及如何操作镜像和容器。接下来我将为你详细介绍步骤: ### 准备工作 1. **获取许可**:确保你有合法的MATLAB许可证,并且该许可证允许你在虚拟化环境中运行软件。 2. **下载官方镜像**:MathWorks提供了一个官方认证过的Docker Hub上的MATLAB基础镜像。你可以通过访问[Docker Hub](https://hub.docker.com/r/mathworks/matlab)找到它并拉取最新版本: ```bash docker pull mathworks/matlab:r20XXa # 将r20XXa替换为您想要的具体版本编号 ``` 3. **创建自定义配置文件(可选)**:如果你需要特定环境设置,则可以准备一些启动脚本、license文件等资源。 4. **安装依赖项**:对于某些Linux发行版来说,在宿主机上还需要提前装好图形界面支持库如`libxrender` `libxtst6` 等用于GUI应用正常显示窗口;如果只打算命令行模式下使用则无需特别处理此部分。 5. **启用X11转发(仅限于GUI需求场景)** :为了能够在远程机器上以图形用户界面对话框形式打开MatLab应用程序窗口,请保证SSH连接时已经开启了-X参数选项并且相应地调整防火墙规则允许TCP端口监听范围内的请求传入本地客户端设备之上。 6. **构建个性化镜像(非必需)**: 根据项目具体情况考虑是否定制化新的docker image,比如预加载常用工具包或修改系统级配置等等。 7. **启动MATLAB容器** - 使用已有的官方镜像直接启动一个交互式的shell会话: ```bash docker run --rm -it \ --env DISPLAY=$DISPLAY \ --volume /tmp/.X11-unix:/tmp/.X11-unix \ # 如果启用了X11转发的话 --name matlab_instance_name_here \ # 自定义实例名称以便管理识别 mathworks/matlab:r20xxa # 版本标签记得换成本地实际拥有的那套完整表述哦~ ``` - 或者按照之前提到的方式新建基于这个base image再额外添加更多个性化的layer形成专属于您的application-specific container images之后再来run新生成出来的image也完全可行! 8. **激活MATLAB** (若未自动完成) 进入到正在运行着的container内部后依照提示信息输入正确的序列号或其他必要的身份验证资料来进行产品授权过程即可正常使用啦~ 9. **持久化数据存储** (推荐做法) 可以为每次实验都单独分配一块挂载点作为workspace来保存所有产生的结果集,同时也能方便日后重复利用之前的计算成果。 示例: ```bash mkdir ~/my_matlab_workspace/ docker run ...options... \ -v ~/my_matlab_workspace/:/root/MATLAB_WORKSPACE\ ... ``` 以上就是在Docker里边部署及初步体验MATLAB全流程概览了,希望能够帮到您!如果您还有其他疑问,欢迎继续咨询。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值