RDK_Docker_Tools/README.md
2026-03-18 11:28:18 +08:00

281 lines
11 KiB
Markdown

- [Docker一键安装脚本](#docker一键安装脚本)
- [支持平台](#支持平台)
- [安装](#安装)
- [测试](#测试)
## Docker一键安装脚本
### 支持平台
1. RDK X5 / RDK X5 Module (RDK OS版本 >= 3.3.3, MiniBoot版本 >= Sep-03-2025)
2. RDK S100 / RDK S100P (RDK OS版本 >= 4.0.4-Beta, Miniboot版本 >= 4.0.4-20251015222314)
### 安装
脚本路径`RDK_Docker_Tools/install_docker.sh`, 该脚本会在RDK板端一键安装docker软件, 配置好网络相关配置.
1. 安装到使用过程无需重启.
2. 安装过程中eth0网络配置不会做做任何修改, ssh不会挂掉.
3. 请使用root用户安装.
4. 请确保板卡能正常访问互联网, `/`目录有2GB可用空间.
```bash
bash install_docker.sh
```
预期输出
```text
============================================================
Docker 一键安装脚本 (Ubuntu 22.04 ARM64/x86_64)
============================================================
[INFO] 检查系统架构...
[OK] 架构: aarch64 (ARM64) ✓
[INFO] 检查运行权限...
[OK] 当前为 root 用户 ✓
[INFO] 检查 eth0 网络接口...
[OK] eth0 状态: UP, IP: 10.112.10.98/24
[INFO] 注意: 本脚本不会修改 eth0 的任何配置
[INFO] 检查 Docker 是否已安装...
[INFO] 检查依赖命令...
[WARN] 以下命令缺失: curl, 尝试安装...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libcurl4 libcurl4-openssl-dev
Suggested packages:
libcurl4-doc libidn11-dev librtmp-dev libssh2-1-dev
The following NEW packages will be installed:
curl
The following packages will be upgraded:
libcurl4 libcurl4-openssl-dev
2 upgraded, 1 newly installed, 0 to remove and 414 not upgraded.
Need to get 190 kB/867 kB of archives.
After this operation, 439 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports jammy-updates/main arm64 curl arm64 7.81.0-1ubuntu1.23 [190 kB]
Fetched 190 kB in 0s (475 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
(Reading database ... 219577 files and directories currently installed.)
Preparing to unpack .../libcurl4-openssl-dev_7.81.0-1ubuntu1.23_arm64.deb ...
Unpacking libcurl4-openssl-dev:arm64 (7.81.0-1ubuntu1.23) over (7.81.0-1ubuntu1.21) ...
Preparing to unpack .../libcurl4_7.81.0-1ubuntu1.23_arm64.deb ...
Unpacking libcurl4:arm64 (7.81.0-1ubuntu1.23) over (7.81.0-1ubuntu1.21) ...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.81.0-1ubuntu1.23_arm64.deb ...
Unpacking curl (7.81.0-1ubuntu1.23) ...
Setting up libcurl4:arm64 (7.81.0-1ubuntu1.23) ...
Setting up curl (7.81.0-1ubuntu1.23) ...
Setting up libcurl4-openssl-dev:arm64 (7.81.0-1ubuntu1.23) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.11) ...
[OK] 依赖命令检查完毕 ✓
[INFO] 检查网络连通性...
[OK] 可访问 Ubuntu ports 源 (ports.ubuntu.com) ✓
[INFO] 更新 apt 软件包缓存...
[OK] apt 缓存更新完毕 ✓
[INFO] 安装必要依赖包...
[INFO] 安装缺失依赖: apt-transport-https
...
[OK] 依赖包就绪 ✓
[INFO] 开始安装 Docker (docker.io)...
...
Adding group `docker' (GID 135) ...
Done.
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.
invoke-rc.d: initscript docker, action "start" failed.
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2026-03-18 11:12:24 CST; 7ms ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Process: 231291 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 231291 (code=exited, status=1/FAILURE)
Setting up dnsmasq-base (2.90-0ubuntu0.22.04.1) ...
Setting up docker-buildx (0.21.3-0ubuntu1~22.04.1) ...
Setting up ubuntu-fan (0.12.16) ...
Created symlink /etc/systemd/system/multi-user.target.wants/ubuntu-fan.service → /lib/systemd/system/ubuntu-fan.service.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.11) ...
[OK] Docker 安装完毕 ✓
[INFO] 检查 iptables 后端兼容性...
update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
update-alternatives: using /usr/sbin/ip6tables-legacy to provide /usr/sbin/ip6tables (ip6tables) in manual mode
[OK] 已切换到 iptables-legacy 后端 ✓
[INFO] 配置 Docker 镜像加速源...
[WARN] 内核缺少 iptable_raw 模块, 将启用 allow-direct-routing 绕过 raw 表限制
[OK] 镜像加速配置完毕 ✓
[INFO] 启动 Docker 服务...
[OK] Docker 服务已通过 systemd 启动 ✓
[INFO] 检查 Docker Hub 及镜像源 DNS 解析...
[OK] DNS hosts 修复完毕 ✓
[INFO] 验证 Docker 安装...
[OK] Docker 版本: Docker version 28.2.2, build 28.2.2-0ubuntu1~22.04.1
[OK] dockerd 进程运行中 ✓
[OK] Docker socket 存在: /var/run/docker.sock ✓
[OK] docker info 执行成功 ✓
[INFO] 验证核心命令可用性...
[OK] docker pull --help ✓
[OK] docker push --help ✓
[OK] docker commit --help ✓
[OK] docker export --help ✓
[OK] docker load --help ✓
[OK] docker images ✓
[OK] docker ps ✓
============================================================
[OK] Docker 安装完成!
============================================================
常用命令速查:
docker pull <镜像> # 拉取镜像
docker push <镜像> # 推送镜像
docker commit <容器> <镜像> # 提交容器为镜像
docker export <容器> -o x.tar # 导出容器
docker load -i <文件.tar> # 加载镜像
docker images # 查看本地镜像
docker ps -a # 查看所有容器
注意事项:
- eth0 网络配置未做任何修改
- 本次安装无需重启系统
- 镜像加速配置: /etc/docker/daemon.json
- Docker 日志: journalctl -u docker 或 /var/log/dockerd.log
```
### 测试
```bash
bash test_docker.sh
```
预期输出
```text
============================================================
Docker 功能测试脚本
============================================================
[INFO] 检查 Docker 服务状态...
[OK] Docker 服务正常 ✓
------------------------------------------------------------
[INFO] [1/5] 测试 docker pull...
------------------------------------------------------------
[INFO] 尝试拉取: hello-world
Using default tag: latest
latest: Pulling from library/hello-world
198f93fd5094: Pull complete
Digest: sha256:85404b3c53951c3ff5d40de0972b1bb21fafa2e8daa235355baf44f33db9dbdd
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
[OK] docker pull 成功 ✓
------------------------------------------------------------
[INFO] [2/5] 测试 docker run...
------------------------------------------------------------
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/
[OK] docker run 成功 ✓
------------------------------------------------------------
[INFO] [3/5] 测试 docker commit...
------------------------------------------------------------
sha256:c2c4ee901ecc7b04b29dadeebc5547450e00ec105d63b7109a462e60628fb866
[OK] docker commit 成功 -> hello-world-committed:test ✓
[OK] commit 镜像验证通过 ✓
------------------------------------------------------------
[INFO] [4/5] 测试 docker export...
------------------------------------------------------------
[OK] docker export 成功 -> /tmp/docker_test_232981/hello-world-export.tar (16K) ✓
------------------------------------------------------------
[INFO] [5/5] 测试 docker save & load...
------------------------------------------------------------
[OK] docker save 成功 -> /tmp/docker_test_232981/hello-world-load.tar (20K) ✓
Untagged: hello-world-committed:test
Deleted: sha256:c2c4ee901ecc7b04b29dadeebc5547450e00ec105d63b7109a462e60628fb866
[INFO] 已删除本地镜像 hello-world-committed:test, 准备 load...
Loaded image: hello-world-committed:test
[OK] docker load 成功, 镜像已恢复 ✓
------------------------------------------------------------
[INFO] [附] docker push 说明
------------------------------------------------------------
[WARN] docker push 需要登录镜像仓库, 本脚本不自动执行
推送到 Docker Hub:
docker login
docker tag hello-world-committed:test <你的用户名>/hello-world:test
docker push <你的用户名>/hello-world:test
推送到私有仓库:
docker tag hello-world-committed:test <仓库地址>/hello-world:test
docker push <仓库地址>/hello-world:test
------------------------------------------------------------
[INFO] 清理测试资源...
------------------------------------------------------------
docker_test_232981
[OK] 容器已清理 ✓
Untagged: hello-world-committed:test
Deleted: sha256:c2c4ee901ecc7b04b29dadeebc5547450e00ec105d63b7109a462e60628fb866
[OK] commit 镜像已清理 ✓
[OK] 临时文件已清理 ✓
============================================================
[OK] 全部测试通过!
============================================================
测试结果汇总:
✓ docker pull - 镜像拉取
✓ docker run - 容器运行
✓ docker commit - 容器提交为镜像
✓ docker export - 容器导出为 tar
✓ docker save - 镜像保存为 tar
✓ docker load - 从 tar 加载镜像
- docker push - 需手动配置仓库后执行
```