現象
ubuntu 下使用docker,禿然一天報了一個錯誤
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
排查
排查了半天,是dockerd啟動的時候指定的API listen 和默認的不一致。
systemctl 啟動的時候,設置的是/run/docker.sock
手動啟動的時候是,/var/run/docker.sock
并且 ubuntu下啟動的時候也沒有看到/run/下面有docker.sock創建
解決
所以有兩種辦法
1.手動啟動dockerd
nohup dockerd &
2.修改systemctl配置文件
vim /lib/systemd/system/docker.service
ExecStart 增加unix listen的socket 配置指定
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H fd:// --containerd=/run/containerd/containerd.sock
3.重啟docker
systemctl restart docker