一、背景
安装完docker和containerd之后,尝试重启docker的时候,报错如下:
systemctl restart docker
Job for docker.service failed because the control process exited with error code. See “systemctl status docker.service” and “journalctl -xe” for details.
使用"systemctl status 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@emc34 ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2023-08-14 09:00:14 CST; 13s ago
Docs: http://docs.docker.com
Process: 1866 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
Main PID: 1866 (code=exited, status=1/FAILURE)
Aug 14 09:00:14 emc34 systemd[1]: Starting Docker Application Container Engine...
Aug 14 09:00:14 emc34 dockerd-current[1866]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives ar...son-file)
Aug 14 09:00:14 emc34 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Aug 14 09:00:14 emc34 systemd[1]: Failed to start Docker Application Container Engine.
Aug 14 09:00:14 emc34 systemd[1]: Unit docker.service entered failed state.
Aug 14 09:00:14 emc34 systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
这里给出了错误原因:
Aug 14 09:00:14 emc34 dockerd-current[1866]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives ar…son-file)
虽然/etc/docker/daemon.json文件内容已在多个机器上配置过,但我还是再检查了下json格式是否合法,其次看地址是否能通。
最后简化到最后这个样子,仍旧是重启docker失败。
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3",
"labels": "production_status",
"env": "os,customer"
}
}
排除不是daemon.json的问题,索性我不删除该配置文件,这时候重启docker就成功了。
可还是不知道啥原因。。。
困扰了好久,,,
因为我的机器环境,除了需安装docker外, 还要求docker-compose。
当要安装docker-comose的时候,会要求docker的版本与之匹配才行。
这会发现docker的版本非常低,于是又后文的docker升级。
通过本文,也提醒我们,当出现我这样的低级错误时,检查下自己的docker版本,及时更新版本是你最好的选择!!
二、升级docker
1、删除旧版本
# 停止docker服务
> systemctl stop docker
# 查看当前版本
> rpm -qa | grep docker
docker-compose-plugin-2.20.2-1.el7.x86_64
docker-buildx-plugin-0.11.2-1.el7.x86_64
docker-ce-cli-24.0.5-1.el7.x86_64
docker-ce-24.0.5-1.el7.x86_64
docker-ce-rootless-extras-24.0.5-1.el7.x86_64
#卸载软件包
yum erase docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
docker-ce
# 删除相关配置文件
find /etc/systemd -name '*docker*' -exec rm -f {} \;
find /etc/systemd -name '*docker*' -exec rm -f {} \;
find /lib/systemd -name '*docker*' -exec rm -f {} \;
#删除已有的镜像和容器
rm -rf /var/lib/docker
rm -rf /var/run/docker
2、安装新版本
# 软件包安装
yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加yum源
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 安装最新版本
yum install docker-ce -y
- 查看docker版本
[root@emc34 opt]# docker version
Client: Docker Engine - Community
Version: 24.0.5
API version: 1.43
Go version: go1.20.6
Git commit: ced0996
Built: Fri Jul 21 20:39:02 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.5
API version: 1.43 (minimum version 1.12)
Go version: go1.20.6
Git commit: a61e2b4
Built: Fri Jul 21 20:38:05 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.22
GitCommit: 8165feabfdfe38c65b599c4993d227328c231fca
runc:
Version: 1.1.8
GitCommit: v1.1.8-0-g82f18fe
docker-init:
Version: 0.19.0
GitCommit: de40ad0
3、设置docker
- 启动并开机自启
> systemctl start docker
> systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
- 配置/etc/docker/daemon.json
这里就略去。其实就是配置你的私有仓库地址。
三、安装docker-compose
- 参考官网https://docs.docker.com/compose/install/standalone/
[root@emc34 bin]# curl -SL https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
[root@emc34 bin]# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
[root@emc34 bin]# docker-compose version
-bash: /usr/local/bin/docker-compose: Permission denied
解决办法:
chmod +x /usr/local/bin/docker-compose
再查看其版本:
[root@emc34 opt]# docker-compose version
Docker Compose version v2.20.3
四、总结
特别想发出一点感想,在没有安装docker-comose前,无论也没想到,daemon.json配置异常竟是因为docker版本过低导致。
本文对安装docker及docker-compose的过程进行了一个记录,希望对你有帮助。