使用 systemd-nspawn 容器化 MATLAB
文档时效性说明
本文为早期笔记,可能存在版本过时、命令失效、链接失效、最佳实践变化等问题。请以官方最新文档为准。
原英文标题:Containerize MATLAB with systemd-nspawn
1. 搭建 Debian 9 环境
切换目录
| sudo su
cd /var/lib/machines
|
安装 debootstrap 和 debian-archive-keyring
| sudo pacman -S debootstrap debian-archive-keyring
|
使用 debootstrap 搭建 debian 环境
| debootstrap --include=systemd-container --components=main,universe stretch matlab-debian9 https://mirrors.163.com/debian
|
设置 Debian 密码
| systemd-nspawn -D ./matlab-debian9/
passwd
|
2. 安装 Firefox 并运行
编辑 /etc/apt/sources.list
| systemd-nspawn -D ./matlab-debian9
deb https://mirrors.163.com/debian stretch main contrib non-free
|
安装 Firefox
退出容器
启用 xhost
复制所有字体:
| cp -a /usr/share/fonts/* /var/lib/machines/matlab-debian9/usr/share/fonts/
|
然后进入容器并运行
然后在容器内运行 Firefox
| systemd-nspawn --setenv=DISPLAY=:0 \
--setenv=XAUTHORITY=~/.Xauthority \
--bind-ro=$HOME/.Xauthority:/root/.Xauthority \
--bind=/tmp/.X11-unix \
-D /var/lib/machines/matlab-debian9 firefox
|
3. 安装 MATLAB
挂载 MATLAB ISO
| sudo mkdir /mnt/matlab
sudo mount -t iso9660 'Matlab98R2020a_Linux 64.iso' /mnt/matlab
|
启动进入容器
| sudo systemd-nspawn -b -D /var/lib/machines/matlab-debian9 --bind=/mnt/matlab
|
如果在 MATLAB 安装过程中遇到 "archive is not a ZIP archive" 错误,移除 -b 选项
安装必要的库
| apt-get install xorg build-essential libgtk2.0-0 libnss3 libasound2
|
设置打开文件数的下限
然后切换到 /mnt/matlab 目录并安装 MATLAB
然后安装并运行 MATLAB
| /usr/local/Polyspace/R2020a/bin/matlab
|
4. 原文(English)
1. 使用 systemd-nspawn 容器化 MATLAB
文档时效性说明
本文为早期笔记,可能存在版本过时、命令失效、链接失效、最佳实践变化等问题。请以官方最新文档为准。
1.1 Set up Debian 9 environment
Change directory
| sudo su
cd /var/lib/machines
|
Install debootstrap and debian-archive-keyring
| sudo pacman -S debootstrap debian-archive-keyring
|
Use debootstrap to set up a debian environment
| debootstrap --include=systemd-container --components=main,universe stretch matlab-debian9 https://mirrors.163.com/debian
|
Set password for Debian
| systemd-nspawn -D ./matlab-debian9/
passwd
|
1.2 Install Firefox and run
Edit /etc/apt/sources.list
| systemd-nspawn -D ./matlab-debian9
deb https://mirrors.163.com/debian stretch main contrib non-free
|
Install Firefox
Exit the container
And enable xhost
Copy all your fonts:
| cp -a /usr/share/fonts/* /var/lib/machines/matlab-debian9/usr/share/fonts/
|
Then shell into the container and run
Then run Firefox inside container
| systemd-nspawn --setenv=DISPLAY=:0 \
--setenv=XAUTHORITY=~/.Xauthority \
--bind-ro=$HOME/.Xauthority:/root/.Xauthority \
--bind=/tmp/.X11-unix \
-D /var/lib/machines/matlab-debian9 firefox
|
1.3 Install MATLAB
mount the MATLAB iso
| sudo mkdir /mnt/matlab
sudo mount -t iso9660 'Matlab98R2020a_Linux 64.iso' /mnt/matlab
|
boot into the container
| sudo systemd-nspawn -b -D /var/lib/machines/matlab-debian9 --bind=/mnt/matlab
|
if you encounter an error message "archive is not a ZIP archive" during MATLAB installation, remove the -b option
install requisite libraries
| apt-get install xorg build-essential libgtk2.0-0 libnss3 libasound2
|
set a lower limit of number of open files by
and then change directory into /mnt/matlab and install MATLAB
then install and run MATLAB
| /usr/local/Polyspace/R2020a/bin/matlab
|