在Raspberry Pi上创建容器
树莓派Raspbian默认是支持LXC容器的,下面我们介绍一下在树莓派上创建并运行容器的过程。
1. 安装LXC相关的package
$ sudo apt-get install -y git lxc lxc-dev
2. 创建LXC网络相关配置文件,这样就配置LXC使能Bridge,容器的网络类型为veth,也就是为容器创建一个virtual ethernet的网络接口,并将这个网络接口加入到host的bridge里面去。
$ vi /etc/default/lxc-net
USE_LXC_BRIDGE="true"
$ mkdir -p ~/.config/lxc
$ vi ~/.config/lxc/default.conf
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.name = eth0
3. 将 UID/GID mapping 加入到 default.conf,通过以下的映射,在容器里uid为0,对应到host里面,uid为100000。所以用户在容器里面有root权限,但是在host侧没有root权限。
$ echo "lxc.id_map = u 0 `grep $USER /etc/subuid | cut -f2 -d:` 65536" >> ~/.config/lxc/default.conf
$ echo "lxc.id_map = g 0 `grep $USER /etc/subgid | cut -f2 -d:` 65536" >> ~/.config/lxc/default.conf
此时 ~/.config/lxc/default.conf 的内容应该如下所示(the 100000 values come from the subordinate UID/GID files at /etc/sub[ug]id files):
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.name = eth0 lxc.id_map = u
lxc.id_map = g
4. 将当前用户加入到 "lxcbr0" bridge的用户列表中
$ echo "$USER veth lxcbr0 10" | sudo tee -a /etc/lxc/lxc-usernet
pi veth lxcbr0
$
5. 运行 lxc 和 lxc-net 服务
$ sudo systemctl start lxc
$ sudo systemctl start lxc-net
6. 重启设备
7. 检查看lxc和lxc-net是否运行正常
$ systemctl status lxc
● lxc.service - LXC Container Initialization and Autoboot Code
Loaded: loaded (/lib/systemd/system/lxc.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri -- :: UTC; 7s ago
Docs: man:lxc-autostart
man:lxc
Process: ExecStop=/usr/lib/arm-linux-gnueabihf/lxc/lxc-containers stop (code=exited, status=/SUCCESS)
Process: ExecStart=/usr/lib/arm-linux-gnueabihf/lxc/lxc-containers start (code=exited, status=/SUCCESS)
Process: ExecStartPre=/usr/lib/arm-linux-gnueabihf/lxc/lxc-apparmor-load (code=exited, status=/SUCCESS)
Main PID: (code=exited, status=/SUCCESS)
CPU: 58ms $ systemctl status lxc-net
● lxc-net.service - LXC network bridge setup
Loaded: loaded (/lib/systemd/system/lxc-net.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri -- :: UTC; 16min ago
Process: ExecStop=/usr/lib/arm-linux-gnueabihf/lxc/lxc-net stop (code=exited, status=/SUCCESS)
Process: ExecStart=/usr/lib/arm-linux-gnueabihf/lxc/lxc-net start (code=exited, status=/SUCCESS)
Main PID: (code=exited, status=/SUCCESS)
CPU: 93ms
8. 创建一个 LXC container,取名为 demo,使用的是“download”类型的容器模板
.
$ lxc-create -t download -n demo -- -d alpine -r 3.7 -a armhf
Setting up the GPG keyring
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs ---
You just created an Alpinelinux 3.7 armhf (20180723_13:) container.
$
9. 用lxc-start启动容器后,用lxc-attach到容器的shell里面,可以继续安装应用程序比如gcc make
在Raspberry Pi上创建容器的更多相关文章
- live555在Raspberry Pi上的点播/直播
1.live555在Raspberry Pi上的点播 live555MediaServer这个实例是个简单的服务器,支持多媒体点播,直接在Raspberry Pi上编译运行,或者通过交叉编译出ARM核 ...
- 让Mono 4在Raspberry Pi上飞
最近公司有项目想要在树莓派上做,代替原来的工控机(我们是把工控主机当作小的主机用,一台小的工控主机最少也要600左右,而树莓派只要200多).于是,公司买了一个Raspberry Pi B+和一个Ra ...
- 在Raspberry Pi上安装XBMC
2013-05-22 XBMC is a free and open source media player application developed by the XBMC Foundation, ...
- Kubernetes集群向指定节点上创建容器
如果需要限制Pod到指定的Node上运行,则可以给Node打标签并给Pod配置NodeSelector. 给节点添加标签 首先查看节点信息 [root@k8s-master ~]# kubectl g ...
- 在树莓派(Raspberry Pi)上编译安装更新版本的Python
Raspiban Wheezy上预装的Python3版本是3.2.3,本文将介绍升级到3.4.3的方法. 此文也适用于安装其它版本(比如最新版本)的Python. 我用的是B+型的树莓派,装的系统是2 ...
- 在Archlinux ARM - Raspberry Pi上安装Google coder
升级软件包 一个 pacman 命令就可以升级整个系统.花费的时间取决于系统有多老.这个命令会同步非本地(local)软件仓库并升级系统的软件包: # pacman -Syu 提示:确保make以及g ...
- Raspberry Pi 上使用WN725N连接WIFI
系统版本 lee@Lee-RPi ~ $ uname -ar Linux Lee-RPi + # PREEMPT Thu Dec :: GMT armv6l GNU/Linux 这个版本的系统,已经集 ...
- 42 在Raspberry Pi上安装dlib表情识别
https://www.jianshu.com/p/848014d8dea9 https://www.pyimagesearch.com/2017/05/01/install-dlib-raspber ...
- 2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐
原文:2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐 image Raspberry Pi** 是一款基于 ARM 的单板计算机,默认运行一款称为 Raspbian ...
随机推荐
- js中clientWidth, scrollWidth, innerWidth, outerWidth,offsetWidth的区别
js中clientWidth, scrollWidth, innerWidth, outerWidth,offsetWidth的属性汇总,测试浏览器:ie7~ie11.chrome 和 firefox ...
- 百万年薪python之路 -- 运算符及while的练习
1.判断下列逻辑语句的结果,一定要自己先分析 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 1 &g ...
- spring boot 整合JPA多数据源
上个文章介绍了spring boot在使用Mybatis持久化技术的时候如何使用多数据源,今天再补充一个使用spring data jpa实现多数据源的使用情况,JPA是一套数据库持久化规范,或者称之 ...
- django-模板之with标签(十二)
就是给传过来的值取个别名.
- Ubuntu 16 server 安装 tensorflow-GPU
目录 显卡驱动安装 CUDA安装 cuDNN安装 tensorflow-gpu安装 本次使用主机配置: cpu:i7-8700K 显卡:GTX-1080Ti 一.安装显卡驱动 打开命令窗口(c ...
- php从数据库获取数据并遍历在表格中
<?php /*连接数据库并以一个数组的形式获得数据*/ header("Content-type:text/html;charset=UTF-8"); $con = mys ...
- Web for pentester_writeup之File Include篇
Web for pentester_writeup之File Include篇 File Include(文件包涵) Example 1 加一个单引号 从报错中我们可以获取如下信息: 当前文件执行的代 ...
- SCOI2005 繁忙的都市 [Luogu P2330]
题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条 ...
- 利用AXI VDMA实现OV5640摄像头采集笔记(二)
导读:摄像头采样图像数据后经过VDMA进入DDR,通过PS部分控制,经过三级缓存,将DDR中保持的图形数据通过VDMA发送出去.在FPGA的接收端口产生VID OUT时序驱动HDMI显示器显示图形. ...
- 解决MacOs 下的 matplotlib 中文字体乱码
在使用 matplotlib 时候,如果表中有中文字体,那么可能会出现无法显示的情况,原因是因为缺少中文字体,可以使用以下步骤解决. 查看 matplotlib 的位置 matplotlib.matp ...