本文基于HD-RK3568-IOT评估板演示Debian系统安装Docker,该方法适用于RK356X全系产品。
HD-RK3568-IOT评估板基于HD-RK3568-CORE 工业级核心板设计(双网口、双CAN、5路串口),接口丰富,适用于工业现场应用需求,亦方便用户评估核心板及CPU 的性能。适用于工业自动化控制、人机界面、中小型医疗分析器、电力等多种行业应用。
1. 检测内核配置
使用 Docker 需要内核支持 CGROUP、BRIDGE 等功能,如果内核中未开启相关配置,安装或运行 Docker 会出现各种错误。Docker开源团队提供了一个脚本https://github.com/moby/moby/blob/master/contrib/check-config.sh,用以检测内核配置是否符合Docker运行的要求。
下载脚本到源码内核目录下。输入如下命令:
chmod 777 check-config.sh
./check-config.sh .config
|注:.config需要在内核配置完后才会生成
check-config.sh使用方法如下:
# ./check_config.sh ./kernel/.config
info: reading kernel config from ./kernel/.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
- CONFIG_CGROUP_CPUACCT: enabled
- CONFIG_CGROUP_DEVICE: enabled
- CONFIG_CGROUP_FREEZER: enabled
- CONFIG_CGROUP_SCHED: enabled
- CONFIG_CPUSETS: enabled
- CONFIG_MEMCG: missing
- CONFIG_KEYS: enabled
- CONFIG_VETH: missing
- CONFIG_BRIDGE: missing
- CONFIG_BRIDGE_NETFILTER: missing
- CONFIG_IP_NF_FILTER: missing
- CONFIG_IP_NF_TARGET_MASQUERADE: missing
- CONFIG_NETFILTER_XT_MATCH_ADDRTYPE: missing
- CONFIG_NETFILTER_XT_MATCH_CONNTRACK: missing
- CONFIG_NETFILTER_XT_MATCH_IPVS: missing
- CONFIG_IP_NF_NAT: missing
- CONFIG_NF_NAT: missing
- CONFIG_POSIX_MQUEUE: missing
Optional Features:
- CONFIG_USER_NS: enabled
- CONFIG_SECCOMP: enabled
- CONFIG_SECCOMP_FILTER: enabled
- CONFIG_CGROUP_PIDS: missing
- CONFIG_MEMCG_SWAP: missing
- CONFIG_MEMCG_SWAP_ENABLED: missing
- CONFIG_BLK_CGROUP: missing
- CONFIG_BLK_DEV_THROTTLING: missing
- CONFIG_CGROUP_PERF: missing
- CONFIG_CGROUP_HUGETLB: missing
- CONFIG_NET_CLS_CGROUP: missing
- CONFIG_CGROUP_NET_PRIO: missing
- CONFIG_CFS_BANDWIDTH: enabled
- CONFIG_FAIR_GROUP_SCHED: enabled
- CONFIG_RT_GROUP_SCHED: missing
- CONFIG_IP_NF_TARGET_REDIRECT: missing
- CONFIG_IP_VS: missing
- CONFIG_IP_VS_NFCT: missing
- CONFIG_IP_VS_PROTO_TCP: missing
- CONFIG_IP_VS_PROTO_UDP: missing
- CONFIG_IP_VS_RR: missing
- CONFIG_SECURITY_SELINUX: missing
- CONFIG_SECURITY_APPARMOR: missing
2. 安装docker
执行以下命令安装Docker:
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
echo "{"registry-mirrors":["https://reg-mirror.qiniu.com/"]}" > /etc/docker/daemon.json
sudo systemctl daemon-reload
sudo systemctl restart docker
3. 配置国内镜像加速
修改配置文件/etc/docker/daemon.json,配置完后重启系统。
{"registry-mirrors": [
"https://ung2thfc.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"]}
4. 验证测试
root@hd-rk3568:~ $ docker run hello-world
若打印信息提示“Hello from Decoker !”则说明已经安装成功,验证通过,
5. Docker常用操作
创建并启动一个新的容器 | docker run | docker run -d --name my-container my-image |
启动已创建的容器 | docker start | docker start my-container |
停止已创建的容器 | docker stop | docker stop my-container |
列出所有正在运行的容器 | docker ps | docker ps -a |
列出所有本地镜像 | docker images | docker images -a |
删除已停止的容器 | docker rm | docker rm my-container |
删除本地镜像 | docker rmi | docker rmi my-image:1.0.0 |
在正在运行的容器中执行命令 | docker exec | docker exec -it my-container bash |