Docker使用
Docker支持
Neardi发布的常规固件通常不满足Docker的要求,因此如果需要,您可以使用SDK打开内核配置并重新编译和烧录内核以支持Docker。
以下示例基于Neardi Ubuntu 20.04,内核配置部分是通用的!
检查内核配置
首先需要检查当前设备内核中缺少哪些Docker所需的配置。check-config.sh脚本可以从github获取。
获取脚本后,开始检查:
# 将脚本复制到SDK的内核目录
cp check-config.sh PathToSDK/kernel/
cd PathToSDK/kernel
chmod +x check-config.sh
# 获取当前内核配置
make ARCH=arm64 rockchip_linux_defconfig
# 检测
./check-config.sh .config
执行后的结果如下,主要有两个部分:
Generally Necessary:
- cgroup hierarchy: properly mounted [/sys/fs/cgroup]
- apparmor: enabled and tools installed
- CONFIG_NAMESPACES: enabled
- CONFIG_NET_NS: enabled
- CONFIG_PID_NS: enabled
- CONFIG_IPC_NS: enabled
- CONFIG_UTS_NS: enabled
- CONFIG_CGROUPS: enabled
......
Optional Features:
- CONFIG_USER_NS: enabled
- CONFIG_SECCOMP: enabled
- CONFIG_SECCOMP_FILTER: enabled
- CONFIG_CGROUP_PIDS: enabled
- CONFIG_MEMCG_SWAP: enabled
......
Generally Necessary:表示必要配置,如果有显示缺失的项目,需要在内核配置中开启。Optional Features:是可选配置,根据需要开启。
开启所需功能
从上述测试结果中了解需要开启的内容后,可以使用make ARCH=arm64 menuconfig进入菜单并搜索相应项目进行开启。请仔细查看菜单中的说明,注意不可选择项目的依赖关系。
开启所有必要配置和一些可选配置后,保存它们:
make ARCH=arm64 savedefconfig
mv defconfig arch/arm64/configs/rockchip_linux_defconfig
之后,编译内核:
# 返回SDK目录
cd ..
# 编译内核
./build.sh kernel
安装Docker
烧录新内核后,可以开始在设备上安装Docker(此安装方法也适用于PC):
- 步骤1:快速安装
# 这里我们只介绍直接使用脚本的快速安装
apt-get update
wget -qO- https://get.docker.com/ | sh
等待安装完成,您应该看到Docker版本信息。
- 步骤2:检查docker存储位置(此步骤仅适用于PC安装docker)
如果您在Neardi设备上安装docker,请跳过步骤2
# 执行
docker info | grep -i dir
# 执行结果
Docker Root Dir: /var/lib/docker
返回的信息显示docker的默认存储位置,在不同计算机上可能不同。镜像和容器占用大量空间,因此如果默认位置没有足够空间,需要将其更改为有充足空间的位置
再次强调,此步骤仅适用于PC,对于Neardi设备,修改此位置会导致docker无法工作,请跳到下一步。
# 首先关闭docker服务
sudo systemctl stop docker
# 修改文件 /lib/systemd/system/docker.service
sudo vim /lib/systemd/system/docker.service
# 在此行末尾添加要修改的位置 --graph /home/neardi/docker/data
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /home/neardi/docker/data
# 重启docker服务
sudo systemctl daemon-reload
sudo systemctl start docker
# 检查位置是否修改成功
docker info | grep -i dir
Docker Root Dir: /home/neardi/docker/data
- 步骤3:将您的用户添加到docker组
sudo usermod -a -G docker neardi
# 添加后重启
sudo reboot
- 步骤4:重启并运行演示测试是否工作:
neardi@LPA3588:~$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/