docker client 无法连接 docker daemon 问题处理记录
Ubuntu 系统,原本通过apt安装了docker-ce。 前两天想用一下desktop,又装了一个desktop。
不知道是不是安装有问题,结果导致docker client连不上docker daemon了
➜ ~ docker ps
Cannot connect to the Docker daemon at unix:///home/wuguozhang/.docker/desktop/docker.sock. Is the docker daemon running?
docker daemon是正常启动了,问题显而易见,是docker cli没有连到正确的socket文件。
首先确认 daemon 的socket文件在哪里, 直接systemctl就可以找到
➜ ~ systemctl list-sockets
LISTEN UNIT ACTIVATES
/dev/rfkill systemd-rfkill.socket systemd-rfkill.service
/run/acpid.socket acpid.socket acpid.service
/run/avahi-daemon/socket avahi-daemon.socket avahi-daemon.service
/run/cups/cups.sock cups.socket cups.service
/run/dbus/system_bus_socket dbus.socket dbus.service
/run/docker.sock docker.socket docker.service
/run/initctl systemd-initctl.socket systemd-initctl.service
/run/snapd-snap.socket snapd.socket snapd.service
/run/snapd.socket snapd.socket snapd.service
/run/systemd/fsck.progress systemd-fsckd.socket systemd-fsckd.service
/run/systemd/journal/dev-log systemd-journald-dev-log.socket systemd-journald.service
/run/systemd/journal/socket systemd-journald.socket systemd-journald.service
/run/systemd/journal/stdout systemd-journald.socket systemd-journald.service
/run/systemd/journal/syslog syslog.socket rsyslog.service
/run/udev/control systemd-udevd-control.socket systemd-udevd.service
/run/uuidd/request uuidd.socket uuidd.service
audit 1 systemd-journald-audit.socket systemd-journald.service
kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
18 sockets listed.
Pass --all to see loaded but inactive sockets, too.
找到是在 /run/docker.sock
,那么问题就变成怎么让 docker cli 连上。
我找了半天,没找到docker cli的配置是在哪里,官网文档也没找到。
最后还是得靠 -h
指令
➜ ~ docker -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/home/wuguozhang/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/wuguozhang/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/wuguozhang/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/wuguozhang/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
(default "/home/wuguozhang/.docker")
最终成功找到一个meta.json文件里有设置
cat /home/wuguozhang/.docker/contexts/meta/fe9c6bd7a66301f49ca9b6a70b217107cd1284598bfc254700c989b916da791e/meta.json
{"Name":"desktop-linux","Metadata":{},"Endpoints":{"docker":{"Host":"unix:///home/wuguozhang/.docker/desktop/docker.sock","SkipTLSVerify":false}}}
最后修改这个文件,把unix://xxxxx更好之后,就全部都正常了
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。