هل سبق لك أن جربت التعليمات البرمجية أو أدوات النظام المساعدة على Linux بطريقة لا تهز النظام الأساسي وتخلعها بالكامل في حالة حدوث خطأ في التعليمات البرمجية يجب تشغيله مع امتيازات الجذر؟
ولكن ماذا عن حقيقة أنه ، على سبيل المثال ، من الضروري اختبار أو تشغيل مجموعة كاملة من الخدمات الصغيرة المختلفة على جهاز واحد؟ مائة أو حتى ألف؟
مع الأجهزة الافتراضية التي يديرها المشرف ، يمكن أن تنجح مثل هذه المهام ، ولكن بأي ثمن؟ على سبيل المثال ، تستهلك الحاوية في LXD استنادًا إلى توزيع Alpine Linux الحد الأدنى من 7.60MB
ذاكرة الوصول العشوائي (RAM) ، وأين تأخذ القسم الجذر بعد بدء التشغيل 9.5MB
!كيف تحب ذلك ، إيلون ماسك؟أوصي بالتعرف على القدرات الأساسية لأنظمة حاويات LXD في Linux
بعد أن أصبح واضحًا بشكل عام ما هي حاويات LXD ، دعنا نمضي قدمًا ونفكر في ما إذا كان هناك معالج منصة حيث سيكون من الآمن تشغيل التعليمات البرمجية للمضيف ، وإنشاء رسومات ، وربط ديناميكي (تفاعليًا) بواجهة مستخدم- الحاجيات مع التعليمات البرمجية الخاصة بك ، أضف التعليمات البرمجية مع النص مع لعبة ورق ...التنسيق؟ شيء مثل بلوق تفاعلي؟واو ... اريدها! تريد! :)
انظر إلى القطة حيث سنطلق JupyterLab في الحاوية - الجيل التالي من واجهة المستخدم بدلاً من Jupyter Notebook القديم ، وكذلك تثبيت وحدات Python مثل NumPy و Pandas و Matplotlib و IPyWidgets التي ستسمح لك بالقيام بكل ما سبق وحفظه في ملف خاص - IPython-laptop .

التنقل
تخطط للاقلاع في المدار ^

سنحدد خطة عمل قصيرة بحيث يسهل علينا تنفيذ المخطط أعلاه:
- Alpine Linux. , .
- —
hostfs
. . . , . , . - Bash, sudo, ,
- Python,
- JupyterLab, , .
, LXD, — LXD — Linux.
— alpine3
, — jupyterlab
:
lxc init alpine3 jupyterlab --profile=default --profile=hddroot
hddroot
root- Storage Pool HDD :
lxc profile show hddroot
config: {}
description: ""
devices:
root:
path: /
pool: hddpool
type: disk
name: hddroot
used_by: []
lxc storage show hddpool
config:
size: 10GB
source: /dev/loop1
volatile.initial_source: /dev/loop1
description: ""
name: hddpool
driver: btrfs
used_by:
- /1.0/images/ebd565585223487526ddb3607f5156e875c15a89e21b61ef004132196da6a0a3
- /1.0/profiles/hddroot
status: Created
locations:
- none
HDD SSD :) ssdroot
.
STOPPED
, init-:
lxc start jupyterlab
LXD -c
columns :
lxc list -c ns4b
+------------+---------+-------------------+--------------+
| NAME | STATE | IPV4 | STORAGE POOL |
+------------+---------+-------------------+--------------+
| jupyterlab | RUNNING | 10.0.5.198 (eth0) | hddpool |
+------------+---------+-------------------+--------------+
IP , default
LXD — Linux.
IP , , . , .
eth0
( ) lxdbr0
NAT , IP — 10.0.5.5
:
lxc config device add jupyterlab eth0 nic name=eth0 nictype=bridged parent=lxdbr0 ipv4.address=10.0.5.5
, :
lxc restart jupyterlab
:
lxc list -c ns4b
+------------+---------+------------------+--------------+
| NAME | STATE | IPV4 | STORAGE POOL |
+------------+---------+------------------+--------------+
| jupyterlab | RUNNING | 10.0.5.5 (eth0) | hddpool |
+------------+---------+------------------+--------------+
:
, man-pages — man man-pages mdocml-apropos less
lxc exec jupyterlab -- apk add bash bash-completion sudo shadow tzdata nano
:
lxc
— LXDexec
— LXD,jupyterlab
—--
— , lxc
apk
— Alpine Linuxadd
—
, - Europe/Moscow
:
lxc exec jupyterlab -- cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
-, tzdata
, , , :
lxc exec jupyterlab -- apk del tzdata
-:
lxc exec jupyterlab -- date
Wed Apr 15 10:49:56 MSK 2020
Bash , .bash_profile
, .bashrc
, .dir_colors
/etc/skel
, Bash , . , Manjaro Linux , , .
skel- . --create-dirs
, :
lxc file push /etc/skel/.bash_profile jupyterlab/etc/skel/.bash_profile --create-dirs
lxc file push /etc/skel/.bashrc jupyterlab/etc/skel/.bashrc
lxc file push /etc/skel/.dir_colors jupyterlab/etc/skel/.dir_colors
root
skel-:
lxc exec jupyterlab -- cp /etc/skel/.bash_profile /root/.bash_profile
lxc exec jupyterlab -- cp /etc/skel/.bashrc /root/.bashrc
lxc exec jupyterlab -- cp /etc/skel/.dir_colors /root/.dir_colors
Alpine Linux /bin/sh
, root
Bash:
lxc exec jupyterlab -- usermod --shell=/bin/bash root
root
. - , :)
lxc exec jupyterlab -- /bin/bash -c "PASSWD=\$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 12); echo \"root:\$PASSWD\" | chpasswd && echo \"New Password: \$PASSWD\""
New Password: sFiXEvBswuWA
— jupyter
JupyterLab
lxc exec jupyterlab -- useradd --create-home --shell=/bin/bash jupyter
:
lxc exec jupyterlab -- /bin/bash -c "PASSWD=\$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 12); echo \"jupyter:\$PASSWD\" | chpasswd && echo \"New Password: \$PASSWD\""
New Password: ZIcbzWrF8tki
, sudo
, jupyter
:
lxc exec jupyterlab -- groupadd --system sudo
lxc exec jupyterlab -- groupmems --group sudo --add jupyter
, jupyter
:
lxc exec jupyterlab -- id -Gn jupyter
jupyter sudo
— , .
sudo
sudo
. , sed
/etc/sudoers
:
lxc exec jupyterlab -- /bin/bash -c "sed --in-place -e '/^#[ \t]*%sudo[ \t]*ALL=(ALL)[ \t]*ALL$/ s/^[# ]*//' /etc/sudoers"
JupyterLab ^
JupyterLab — Python , . , JupyterLab pip
, , , , — python3 python3-dev gcc libc-dev zeromq-dev
:
lxc exec jupyterlab -- apk add python3 python3-dev gcc libc-dev zeromq-dev
python- pip
:
lxc exec jupyterlab -- python3 -m pip install --upgrade pip setuptools wheel
JupyterLab pip
:
lxc exec jupyterlab -- python3 -m pip install jupyterlab
JupyterLab jupyterlab, , .
NodeJS — NPM, JupyterLab :
lxc exec jupyterlab -- apk add nodejs npm
JupyterLab , jupyter
. , , . , JUPYTERLAB_DIR
jupyter
, .bashrc
, :
lxc exec jupyterlab -- su -l jupyter -c "echo -e \"\nexport JUPYTERLAB_DIR=\$HOME/.local/share/jupyter/lab\" >> .bashrc"
— JupyterLab:
lxc exec jupyterlab -- su -l jupyter -c "export JUPYTERLAB_DIR=\$HOME/.local/share/jupyter/lab; jupyter labextension install --no-build @jupyter-widgets/jupyterlab-manager"
JupyterLab, :
toc
— Table of Contents, /jupyterlab-horizon-theme
— UIjupyterlab_neon_theme
— UIjupyterlab-ubu-theme
— :) , GitHub
, , :
lxc exec jupyterlab -- su -l jupyter -c "export JUPYTERLAB_DIR=\$HOME/.local/share/jupyter/lab; jupyter labextension install --no-build @jupyterlab/toc @mohirio/jupyterlab-horizon-theme @yeebc/jupyterlab_neon_theme"
lxc exec jupyterlab -- su -l jupyter -c "wget -c https://github.com/microcoder/jupyterlab-ubu-theme/archive/master.zip"
lxc exec jupyterlab -- su -l jupyter -c "unzip -q master.zip && rm master.zip"
lxc exec jupyterlab -- su -l jupyter -c "export JUPYTERLAB_DIR=\$HOME/.local/share/jupyter/lab; jupyter labextension install --no-build jupyterlab-ubu-theme-master"
lxc exec jupyterlab -- su -l jupyter -c "rm -r jupyterlab-ubu-theme-master"
, , --no-build
. :
lxc exec jupyterlab -- su -l jupyter -c "export JUPYTERLAB_DIR=\$HOME/.local/share/jupyter/lab; jupyter lab build"
:
lxc exec jupyterlab -- su -l jupyter -c "jupyter lab clean && jlpm cache clean && npm cache clean --force"
JupyterLab. , , JupyterLab bash' , , :)
jupyter
:
lxc exec jupyterlab -- su -l jupyter
JupyterLab :
[jupyter@jupyterlab ~]$ jupyter lab --ip=0.0.0.0 --no-browser
web- http://10.0.5.5:8888 token . , Login. , , , JupyterLab development :

, JupyterLab , NodeJS , . /home
, , , . JupyterLab.
IPython- ( JupyterLab) — /home/jupyter
, () , , JupyterLab hotkey — CTRL+C
y
. jupyter
CTRL+D
.
, , :
lxc config device add
—jupyter
—hostfs
— . .disk
—path
— LXDsource
— , .
lxc config device add jupyterlab hostfs disk path=/mnt/hostfs source=/home/dv/projects/ipython-notebooks
/home/dv/projects/ipython-notebooks
UID SubUID + UID
, . LXD — Linux.
, jupyter
, $USER
:
sudo chown 1001000:$USER /home/dv/projects/ipython-notebooks
Hello, World! ^
JupyterLab, --notebook-dir
/mnt/hostfs
:
jupyter lab --ip=0.0.0.0 --no-browser --notebook-dir=/mnt/hostfs
http://10.0.5.5:8888 :

Python Hello World!
. CTRL+ENTER
"play" JupyterLab :

, , Python- ( ) Python JupyterLab, , :)
P.S. , Jupyter Jupyter Notebook JupyterLab. /tree
, /lab
, :
Python ^
Python NumPy, Pandas, Matplotlib, IPyWidgets JupyterLab.
Python pip
Alpine Linux:
g++
— , C++ Pythonfreetype-dev
— Python Matplotlib
:
lxc exec jupyterlab -- apk add g++ freetype-dev
, Alpine Linux NumPy , :
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly
, , , :
lxc exec jupyterlab -- apk add py3-numpy py3-numpy-dev
Python- pip
. , . ~15 :
lxc exec jupyterlab -- python3 -m pip install pandas matplotlib ipywidgets
:
lxc exec jupyterlab -- rm -rf /home/*/.cache/pip/*
lxc exec jupyterlab -- rm -rf /root/.cache/pip/*
JupyterLab ^
JupyterLab, , . CTRL+C
y
, JupyterLab "", Enter
:
jupyter lab --ip=0.0.0.0 --no-browser --notebook-dir=/mnt/hostfs
http://10.0.5.5:8888/lab , :
%matplotlib inline
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np
def f(m, b):
plt.figure(2)
x = np.linspace(-10, 10, num=1000)
plt.plot(x, m * x + b)
plt.ylim(-5, 5)
plt.show()
interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
, IPyWidgets UI- , Matplotlib :

IPyWidgets
, . JupyterLab " ", :) , , Bash :)
, :

! . !
UPDATE: 15.04.2020 18:30 — "Hello, World!"
UPDATE: 16.04.2020 10:00 — JupyterLab
UPDATE: 16.04.2020 10:40 — " "