在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 ...
随机推荐
- FileZilla Server超详细配置
FileZilla Server下载安装完成后,必须启动软件进行设置,由于此软件是英文,本来就是一款陌生的软件,再加上英文(注:本站提供中文版本,请点击下载),配置难度可想而知,站长从网上找到一篇非常 ...
- 百万年薪python之路 -- socket()模块的用法
socket()模块的用法: import socket socket.socket(socket_family,socket_type,protocal=0) socket_family 可以是 A ...
- 优化 .net core 应用的 dockerfile
优化 .net core 应用的 dockerfile Intro 在给 .net core 应用的写 dockerfile 的时候一直有个苦恼,就是如果有很多个项目,在 dockerfile 里写起 ...
- django-表单之模型表单(三)
models.py-->forms.py-->views.py(get)--index.html-->views.py(post)-->home.html urls.py fr ...
- fenby C语言 P12
条件语句的嵌套 注意格式对齐 #include <stdio.h> int main(){ int score=67; if(score<=100&&score> ...
- SpringCloud之Zuul过滤器实现登录鉴权实战(十一)
自定义zuul过滤器实现登录鉴权实战 1.新建filter包 2.新建类继承ZuulFilter,重写方法 3.在类顶部加注解@Comment让spring扫描 /** * @author WGR * ...
- 7、pytest -- 捕获标准输出和标准错误输出
目录 1. 标准输出/标准错误输出/标准输入的默认捕获行为 2. 修改和去使能捕获行为 2.1. 文件描述符级别的捕获行为(默认) 2.2. sys级别的捕获行为 2.3. 去使能捕获行为 3. 使用 ...
- forEach,map,every,some,filter简单用法实例
平时简单总结:不足之处还望见谅: 实例: 11.1 forEach:只能进行取值操作,不能进行修改 arr.forEach(function(element,index,arr){});//注意参数: ...
- JNI技术实现--Java调C/C++
废话不多说,首先我们来看Java调用C/C++步骤: 1.编写Java代码,在代码中使用native关键字标明该方法是调用本地库,不需要实现. 2.使用javah -jni 命令,生成对应的头文件,此 ...
- strGame:博弈论,trie
挺有意思的一道题.初探博弈论. 最好自己思考? 我们先考虑只有1轮游戏的情况. 这题明显要在字符串上一位一位地走,所以对字符串建立起trie. 最终建立起的trie的叶节点就是必败位置了. 对于非叶节 ...