如题,使用docker时提示如下操作。可能是服务器重启而docker未重启造成。
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
可使用如下操作查看docker状态。
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com
状态为:inactive,说明需要重启。
systemctl start docker
- 如果重启正常
再次使用上上一步命令查看docker状态
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-01-12 10:01:36 CST; 2min 33s ago
Docs: https://docs.docker.com
Main PID: 1646 (dockerd)
Tasks: 9
Memory: 163.1M
CGroup: /system.slice/docker.service
└─1646 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
此时,发现dockers已经正常运行。
- 如果重启异常如下
systemctl start docker
Failed to start docker.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status docker.service' for details.
则需要去创建文件
sudo vi /etc/docker/daemon.json
内容如下
{
"registry-mirrors": ["https://us6h4sfn.mirror.aliyuncs.com","http://hub-mirror.c.163.com","https://registry.docker-cn.com"] ,
"data-root": "/usr/docker.images.data"
}
还有的人,需要包含(未验证)
"storage-driver": "devicemapper"
然后重启docker服务,并查询,发现启动成功了。
sudo systemctl restart docker
sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2022-10-27 01:30:15 UTC; 10s ago
Docs: https://docs.docker.com
Process: 3057 ExecStartPre=/usr/libexec/docker/docker-setup-runtimes.sh (code=exited, status=0/SUCCESS)
Process: 3055 ExecStartPre=/bin/mkdir -p /run/docker (code=exited, status=0/SUCCESS)
Main PID: 3059 (dockerd)
Tasks: 8
Memory: 94.0M
CGroup: /system.slice/docker.service
└─3059 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --default-ulimit nofile=32768:65536
附录:
如果docker未安装,可先使用如下命令安装docker。(适用于centos)
sudo yum install docker
参见: