概述
很多人会觉得宿主机上安装了新版本的 Kubernetes 之后,因为移除了 Docker 的依赖,所以就不能在宿主机安装 Docker 了。虽然 nerdctl 或者 ctr 这些命令可以跟之前使用 Docker 的客户端差不多,但对于习惯 Docker 的用户来说,最理想还是可以继续使用 Docker 的客户端。当然不是说安装了 Containerd 的 Kubernetes 集群之后就不能安装的 Docker 的,其实也是可以的,下面具体介绍一下操作的方式和注意的事项。
操作
主要的操作就是先下载 Docker 的二进制,因为 Containerd 已经提前安装好了,所以就没有必要通过 yum 或者 apt-get 的方式来安装了,否则有可能会影响原来的配置。
1
2
3
4
|
curl -LO https://download.docker.com/linux/static/stable/x86_64/docker-27.3.1.tgz
tar zxvf docker-27.3.1.tgz
cp docker/docker* /usr/bin/
dockerd &
|
通过上面的操作,可以将 dockerd 作为后台进程运行,这样 Docker 的客户端命令就可以正常使用了。另外如果想让 Docker 像之前的方式,比如 Service 的方式,可以支持宿主机重启后自动拉起 dockerd,又不想影响 Kubernetes 和 Containerd 的话,可以创建下面的 Service 文件,并且安装和使用,另外就是注意启动 dockerd 的启动参数 --containerd
需要指定当前的 Containerd 的 UDS 文件地址。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket
[Service]
Type=notify
Environment="HTTP_PROXY="
Environment="HTTPS_PROXY="
Environment="NO_PROXY="
# 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/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# 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
OOMScoreAdjust=-500
|
参考资料
- Install daemon and client binaries on Linux