想在容器中测试一下docker的简易离线配置步骤,结果遇见几个莫名其妙的错误,记录下排错过程供后续参考。
这是一个centos7.9的容器,配置好yum源,包括os和epel,如下:
cat /etc/yum.repos.d/centos.repo
[centos]
name=centos
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
下载如下docker-compose安装包:
containerd.io-1.6.4-3.1.el7.x86_64.rpm
container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm
docker-ce-20.10.15-3.el7.x86_64.rpm
docker-ce-cli 20.10.15-3.el7.x86_64.rpm
docker-ce-rootless-extras-20.10.15-3.el7.x86_64.rpm
docker-compose-plugin-2.5.0-3.el7.x86_64.rpm
docker-scan-plugin-0.17.0-3.el7.x86_64.rpm
fuse3-libs-3.6.1-4.el7.x86_64.rpm
fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
slirp4netns-0.4.3- 4.el7_8.x86_64.rpm
离线安装:
yum localinstall *.rpm
启动docker报错,没有足够的回环设备可用:
ERRO[2022-09-07T11:44:08.607124280Z] There are no more loopback devices available.
ERRO[2022-09-07T11:44:08.607170072Z] [graphdriver] prior storage driver devicemapper failed: loopback attach failed
failed to start daemon: error initializing graphdriver: loopback attach failed
手动创建回环设备:
for i in {0..6}
do
mknod -m 0660 /dev/loop$i b 7 $i
done
启动docker再次报错,没有ext4文件系统支持:
INFO[2022-09-08T00:37:15.652719473Z] Error while creating filesystem ext4 on device docker-0:55-2177230803-base: exec: "mkfs.ext4": executable file not found in $PATH storage-driver=devicemapper
ERRO[2022-09-08T00:37:15.652785437Z] [graphdriver] prior storage driver devicemapper failed: exec: "mkfs.ext4": executable file not found in $PATH
failed to start daemon: error initializing graphdriver: exec: "mkfs.ext4": executable file not found in $PATH
确认没有ext4:只有默认的xfs?
ll /usr/sbin/mkfs*
-rwxr-xr-x 1 root root 11520 Sep 30 2020 /usr/sbin/mkfs
-rwxr-xr-x 1 root root 37024 Sep 30 2020 /usr/sbin/mkfs.cramfs
-rwxr-xr-x 1 root root 37136 Sep 30 2020 /usr/sbin/mkfs.minix
安装ext4文件系统即可启动docker:
yum provides mkfs.ext4
yum install e2fsprogs -y
此时的问题是,docker显示状态正常,但是无法正常连接:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
但是如果采用直接命令行 dockerd 的方式,是可以的,说明docker基本安装没有问题,但是使用 systemctl start docker 的方式就没法连接docker!
因此这应该是docker服务配置文件的问题了,经查询,默认的docker服务配置文件是:
/usr/lib/systemd/system/docker.service
其中服务启动的命令行是:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
改为如下即可,即去掉了 "-H fd://" 部分:
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock
这是为什么呢?留待后续。
【2022-9-29】经后来验证,不去掉这个handle标识,实际是可以的,可能要等待一个初始化时间!