安装过程

首先去网站下载docker安装包,我这里选择和公司服务器上的docker一致的版本:docker-19.03.3.tgz,然后上传到需要安装docker的服务器。

1)首先解压压缩包,此时会在当前目录下生成一个docker目录,在docker目录下全是可执行文件。

tar -xzvf docker-19.03.3.tgz
docker/
docker/docker
docker/runc
docker/ctr
docker/dockerd
docker/docker-init
docker/docker-proxy
docker/containerd-shim-runc-v2
docker/containerd-shim
docker/containerd

2)将1)中解压得到的二进制文件全复制到/usr/bin目录下。

cd docker 
cp * /usr/bin/

3)将docker注册成系统服务

执行“vim /etc/systemd/system/docker.service”命令,然后在文件中添加以下内容,退出并保存。
下面的配置需要注意的是 : ExecStart=/usr/bin/dockerd,也就是说指明了dockerd所在位置。我第一次安装没有将1)中所有的二进制复制到/usr/bin/,

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

[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

给文件增加可执行权限

chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload 

4)设置开机自启动

systemctl enable docker.service

5) 启动docker

systemctl start docker

6)测试docker是否启动

docker ps

如果打印出如下信息,则表示正确安装,如果提示Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?,则表示docker没有安装正确。

过程中遇到的错误

1)在将docker注册成系统服务时,需要注意的是 : ExecStart=/usr/bin/dockerd,也就是说指明了dockerd所在位置。我第一次安装没有将1)中所有的二进制复制到/usr/bin/下,造成在执行systemctl start docker时,报错:Process: 28545 ExecStart=/usr/bin/dockerd (code=exited, status=203/EXEC)。这是因为程序没有在/usr/bin下找到dockerd可执行程序,因此报错。

Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
● docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: start-limit) since 四 2020-11-12 11:27:15 CST; 37s ago
Docs: https://docs.docker.com
Process: 28545 ExecStart=/usr/bin/dockerd (code=exited, status=203/EXEC)
Main PID: 28545 (code=exited, status=203/EXEC)
11月 12 11:27:15 host-90-0-0-80 systemd[1]: Failed to start Docker Application Container Engine.
11月 12 11:27:15 host-90-0-0-80 systemd[1]: Unit docker.service entered failed state.
11月 12 11:27:15 host-90-0-0-80 systemd[1]: docker.service failed.
11月 12 11:27:15 host-90-0-0-80 systemd[1]: docker.service holdoff time over, scheduling restart.
11月 12 11:27:15 host-90-0-0-80 systemd[1]: start request repeated too quickly for docker.service
11月 12 11:27:15 host-90-0-0-80 systemd[1]: Failed to start Docker Application Container Engine.
11月 12 11:27:15 host-90-0-0-80 systemd[1]: Unit docker.service entered failed state.
11月 12 11:27:15 host-90-0-0-80 systemd[1]: docker.service failed.

2)关于 /etc/docker/daemon.json 的错误
刚开始遇到1)的错误时,copy了公司其他docker服务器上的 /etc/docker/daemon.json,报错: Process: 3706 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)。此时主要观察到daemon.json的 “data-root”: “/data/docker”, 然而在安装的时候,我在/data/docker 下放置了解压的二进制文件,导致相关目录无法创建,从而导致docker在读取 /etc/docker/daemon.json后发生错误。

[root@tt init.d]# service docker start
Redirecting to /bin/systemctl start docker.service
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
# 根据提示使用相关命令查看启动时错误日志
[root@tt init.d]# systemctl status docker.service
docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Mon 2018-07-02 22:20:05 EDT; 10s ago
Docs: https://docs.docker.com
Process: 3706 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
Main PID: 3706 (code=exited, status=1/FAILURE)
Jul 02 22:20:05 localhost systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Jul 02 22:20:05 localhost systemd[1]: Failed to start Docker Application Container Engine.
Jul 02 22:20:05 localhost systemd[1]: Unit docker.service entered failed state.
Jul 02 22:20:05 localhost systemd[1]: docker.service failed.
Jul 02 22:20:05 localhost systemd[1]: docker.service holdoff time over, scheduling restart.
Jul 02 22:20:05 localhost systemd[1]: start request repeated too quickly for docker.service
Jul 02 22:20:05 localhost systemd[1]: Failed to start Docker Application Container Engine.
Jul 02 22:20:05 localhost systemd[1]: Unit docker.service entered failed state.
Jul 02 22:20:05 localhost systemd[1]: docker.service failed.

最后修改:2024 年 11 月 22 日
如果觉得我的文章对你有用,请随意赞赏