自学内容网 自学内容网

我的docker随笔45:在龙芯平台安装docker

本文介绍在龙芯平台安装docker。

前言

2017年下半年开始接触docker时,那会李大锤刚刚会爬,而今年(2024年)下半年,李大锤已经是一个经常考得C并且经常和妹妹吵架的二年级学生了。这么多年就过去,docker一直陪伴着我的工作,正如我一直陪伴着大锤大妞的成长一样。

最近手上正好有台龙芯机器,恰好要做适配,刚好想研究不同平台的容器部署,于是就趁机尝试安装docker

环境

本文使用的软硬件说明如下。

处理芯片为Loongson-3A5000-LL,操作系统为麒麟桌面版,龙芯环境为旧世界。

CPU详情:

# cat /proc/cpuinfo 
system type             : generic-loongson-machine
processor               : 0
package                 : 0
core                    : 0
cpu family              : Loongson-64bit
model name              : Loongson-3A5000-LL
CPU Revision            : 0x14
FPU Revision            : 0x00
CPU MHz                 : 1800.00
BogoMIPS                : 3600.00
TLB entries             : 2112
Address sizes           : 48 bits physical, 48 bits virtual
isa                     : loongarch32 loongarch64
features                : cpucfg lam ual fpu lsx lasx crc32 complex crypto lvz lbt_x86 lbt_arm lbt_mips
hardware watchpoint     : yes, iwatch count: 8, dwatch count: 8
...

操作系统详情:

# cat /etc/os-release 
NAME="Kylin"
VERSION="银河麒麟桌面操作系统V10 (SP1)"
VERSION_US="Kylin Linux Desktop V10 (SP1)"
ID=kylin
ID_LIKE=debian
PRETTY_NAME="Kylin V10 SP1"
VERSION_ID="v10"
HOME_URL="http://www.kylinos.cn/"
SUPPORT_URL="http://www.kylinos.cn/support/technology.html"
BUG_REPORT_URL="http://www.kylinos.cn/"
PRIVACY_POLICY_URL="http://www.kylinos.cn"
VERSION_CODENAME=kylin
UBUNTU_CODENAME=kylin
PROJECT_CODENAME=V10SP1
KYLIN_RELEASE_ID="2403"

下载

docker的官方下载地址只提供了x86和arm架构的安装包。在龙芯系统里用apt-get install docker-ce命令安装,提示无候选包。经过搜索,在网上找到相关帖子,顺道找到github上已经编译好的安装包。

龙芯版docker安装包下载为:https://github.com/wojiushixiaobai/docker-ce-binaries-loongarch64/releases,本文选用今年(2024年)1月下旬发布的版本,文件名为docker-25.0.0.tgz。同时找该版本相近时间发布的docker-compose,地址为:https://github.com/wojiushixiaobai/compose-loongarch64/releases,版本是v2.24.0

安装

下载安装包后将其上传到机子。

解压文件

解压到相应目录:

tar xf docker-25.0.0.tgz -C /tmp
sudo mv /tmp/docker/* /usr/local/bin/

mkdir -p /usr/libexec/docker/cli-plugins/
cp docker-compose-linux-loongarch64 /usr/libexec/docker/cli-plugins/docker-compose

chmod +x /usr/libexec/docker/cli-plugins/docker-compose

注意,上面是拷贝docker目录里的二进制可执行文件到/usr/local/bin/。该目录文件如下:

$ ls /usr/local/bin/
containerd  containerd-shim-runc-v2  ctr  docker  dockerd  docker-init  docker-proxy  runc
添加配置

新建Docker 配置文件为/etc/docker/daemon.json 。默认不存在。

# mkdir /etc/docker
# cat > /etc/docker/daemon.json <<-EOF
{
  "registry-mirrors": [
    "https://a8qh6yqv.mirror.aliyuncs.com",
    "http://hub-mirror.c.163.com"
  ],
  "insecure-registries": [
    "172.18.18.168:5000",
    "10.10.1.8:5000"
  ],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "data-root": "/data/docker",
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"3"}
}
EOF

上述配置文件指定了docker镜像存储在/data/docker中,并指定了加速器和内部镜像仓库。根据实际情况修改。

新建systemctl启动所需的/etc/systemd/system/docker.service文件,内容如下:

# vim /etc/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/local/bin/dockerd --default-ulimit nofile=65535:65535
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
启动服务

启动:

systemctl start docker

查看状态:

systemctl status docker

输出结果:

# systemctl status docker
Warning: The unit file, source configuration file or drop-ins of docker.service changed on disk. Run 'systemctl daemon-reload' to reload units.
● docker.service - Docker Application Container Engine
     Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2024-11-12 14:39:46 CST; 9s ago
       Docs: https://docs.docker.com
   Main PID: 91011 (dockerd)
      Tasks: 21 (limit: 19233)
     Memory: 36.2M
     CGroup: /system.slice/docker.service
             ├─91011 /usr/local/bin/dockerd --default-ulimit nofile=65535:65535
             └─91022 containerd --config /var/run/docker/containerd/containerd.toml

设置开机启动:

systemctl daemon-reload
systemctl enable docker
查看进程

docker启动后,会运行2个进程服务,除了dockerd进程外,还在containerd进程。如下:

$ ps aux | grep docker
root       91011  0.0  0.3 2023520 58832 ?       Ssl  14:39   0:00 /usr/local/bin/dockerd --default-ulimit nofile=65535:65535
root       91022  0.0  0.1 1929712 30576 ?       Ssl  14:39   0:00 containerd --config /var/run/docker/containerd/containerd.toml
修改权限

如果使用普通用户执行docker命令,会出现错误,如下:

$ docker ps
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

这是因为普通用户权限不足造成的。先看一下出错信息/var/run/docker.sock文件的权限。

$ ll /var/run/docker.sock
srw-rw---- 1 root root 0 11月 12 14:39 /var/run/docker.sock=

该文件权限为root,所属root组。离线安装的docker没有docker组,因此将该文件权限修改如下:

sudo chmod 777  /var/run/docker.sock

这样普通用户能执行docker命令了。

查看版本号:

$ docker version
Client:
 Version:           25.0.0
 API version:       1.44
 Go version:        go1.21.5
 Git commit:        e758fe5
 Built:             Sun Jan 21 04:36:23 2024
 OS/Arch:           linux/loong64
 Context:           default

Server:
 Engine:
  Version:          25.0.0
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.5
  Git commit:       615dfdf67264ed5b08dd5e86657bf0e580731cea
  Built:            Sun Jan 21 04:36:55 2024
  OS/Arch:          linux/loong64
  Experimental:     false
 containerd:
  Version:          v1.7.12
  GitCommit:        71909c1814c544ac47ab91d2e8b84718e517bb99
 runc:
  Version:          1.1.11
  GitCommit:        v1.1.11-0-g4bccb38
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

测试

曾几何时,hub.docker.com可以畅通访问并能下载镜像,现在已经无法访问了。真是岁月不居,时节如流,日月如梭,沧海桑田。

幸好,龙芯有官方的镜像仓库,地址为https://lcr.loongnix.cn/search。搜索未发现有gcc镜像,但有debian镜像。

尝试拉取镜像:

$ time docker pull lcr.loongnix.cn/library/debian
Using default tag: latest
latest: Pulling from library/debian
5755e6e26c6c: Pull complete 
Digest: sha256:0356df4e494bbb86bb469377a00789a5b42bbf67d5ff649a3f9721b745cbef77
Status: Downloaded newer image for lcr.loongnix.cn/library/debian:latest
lcr.loongnix.cn/library/debian:latest

real    33m7.466s
user    0m0.139s
sys     0m0.022s

运行之:

$ docker run -it --rm lcr.loongnix.cn/library/debian bash
root@136affeb24e5:/# 
exit

$ docker run -it --rm lcr.loongnix.cn/library/debian bash
root@9086b74f2d84:/# 
exit

使用bash直接退出了。换sh试试:

$ docker run -it --rm lcr.loongnix.cn/library/debian sh
# uname 

d^C^C^C^C^C^C^Z^C

能进入容器,但执行命令卡住。尝试在启动容器时执行命令:

$ docker run -it --rm lcr.loongnix.cn/library/debian uname -a
Linux 264b55e053b0 5.4.18-110-generic #99-KYLINOS SMP Fri Mar 29 09:24:59 UTC 2024 loongarch64 GNU/Linux

查看镜像发行版本信息,如下:

$ docker run -it --rm lcr.loongnix.cn/library/debian cat /etc/issue
Debian GNU/Linux trixie/sid \n \l

后面在其它帖子找到GitHub 镜像仓库(ghcr.io),上面有debian镜像,尝试拉取:

$ docker pull ghcr.io/loong64/debian:trixie
trixie: Pulling from loong64/debian
7a50cba388e3: Pull complete 
Digest: sha256:0aebb2809e98b7eeec4d8cc51b79bac709b84ea563c800d752b96b6a57d8937f
Status: Downloaded newer image for ghcr.io/loong64/debian:trixie
ghcr.io/loong64/debian:trixie

查看镜像发行版本信息,如下:

$ docker run -it --rm ghcr.io/loong64/debian:trixie cat /etc/issue
Debian GNU/Linux trixie/sid \n \l

两者应该是同源构建的,查看当前镜像列表,2者体积相差不大。

$ docker images
REPOSITORY                       TAG       IMAGE ID       CREATED        SIZE
ghcr.io/loong64/debian           trixie    47801f83a510   36 hours ago   126MB
lcr.loongnix.cn/library/debian   latest    53a1255560be   5 months ago   122MB

在相同网络,相近时间进行相同操作,一个耗时30秒,一个耗时30分钟,但不懂为何官方的仓库下载如此耗时。

小结

通过本文的实践,可以成功在龙芯机器上安装docker,不过目前还没有找到合用的镜像。原因待查,后面还要继续研究。

问题及解决

直接执行dockerd命令,提示如下:

# /usr/local/docker/dockerd 
invalid userland-proxy-path: userland-proxy is enabled, but userland-proxy-path is not set

userland-proxy设置为false即可:

/usr/local/bin/dockerd --userland-proxy=false

不过,使用systemctl启动时,无法添加userland-proxy标志也能启动。

参考资料
  • 参考资料:https://bbs.loongarch.org/d/248-loongnix-docker/3
  • 龙芯docker 安装包下载:https://github.com/wojiushixiaobai/docker-ce-binaries-loongarch64/releases
  • 龙芯docker-compose 安装包下载:https://github.com/wojiushixiaobai/compose-loongarch64/releases
  • docker.service文件:https://github.com/wojiushixiaobai/docker-ce-binaries-loongarch64/blob/master/docker.service
  • 龙芯的镜像仓库:https://cr.loongnix.cn/search
  • docker官方下载地址:https://download.docker.com/linux/static/stable/

原文地址:https://blog.csdn.net/subfate/article/details/143744143

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!