当前位置: 首页 > 知识库问答 >
问题:

Docker正在运行但Py魅力无法连接到Docker守护进程

袁高明
2023-03-14

我是docker的新手,在这里还没有找到一个问题来回答我遇到的问题。

我正在尝试使用Pycharm运行dockerfile,以便调试docker中的特定程序。我在pycharm中打开了dockerfile,并创建了运行dockerfile的配置。运行程序会在“服务”选项卡下显示错误消息:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

在我搜索了这个问题之后,我发现了这个线程:无法连接到unix上的Docker守护程序:/var/run/Docker。短袜docker守护程序是否正在运行?

上面说我应该运行sudo dockerd。在出现一些错误后,我完全卸载了docker,然后再次安装。安装后,我运行:

systemctl status docker

输出为:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-09-26 15:06:22 IDT; 59s ago
     Docs: https://docs.docker.com
 Main PID: 24888 (dockerd)
    Tasks: 21
   CGroup: /system.slice/docker.service
           └─24888 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

因此,我使用sudo service docker stop停止了它,我再次运行了systemctl status docker,它确实停止了:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2020-09-26 15:09:29 IDT; 16s ago
     Docs: https://docs.docker.com
  Process: 24888 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=0/SUCCES
 Main PID: 24888 (code=exited, status=0/SUCCESS)

Sep 26 15:06:21 DL-2 dockerd[24888]: time="2020-09-26T15:06:21.919021419+03:00" level=info msg="Loading containers: done."
Sep 26 15:06:22 DL-2 dockerd[24888]: time="2020-09-26T15:06:22.265996712+03:00" level=info msg="Docker daemon" commit=4484c46d9
Sep 26 15:06:22 DL-2 dockerd[24888]: time="2020-09-26T15:06:22.266253446+03:00" level=info msg="Daemon has completed initializa
Sep 26 15:06:22 DL-2 dockerd[24888]: time="2020-09-26T15:06:22.642407513+03:00" level=info msg="API listen on /var/run/docker.s
Sep 26 15:06:22 DL-2 systemd[1]: Started Docker Application Container Engine.
Sep 26 15:09:29 DL-2 systemd[1]: Stopping Docker Application Container Engine...
Sep 26 15:09:29 DL-2 dockerd[24888]: time="2020-09-26T15:09:29.427473508+03:00" level=info msg="Processing signal 'terminated'"
Sep 26 15:09:29 DL-2 dockerd[24888]: time="2020-09-26T15:09:29.428067483+03:00" level=info msg="stopping event stream following
Sep 26 15:09:29 DL-2 dockerd[24888]: time="2020-09-26T15:09:29.428325869+03:00" level=info msg="Daemon shutdown complete"
Sep 26 15:09:29 DL-2 systemd[1]: Stopped Docker Application Container Engine.

所以我运行了sudo dockerd,它似乎运行良好:

INFO[2020-09-26T15:11:03.918879915+03:00] Starting up                                  
INFO[2020-09-26T15:11:03.919388821+03:00] detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv.conf 
INFO[2020-09-26T15:11:03.919768789+03:00] parsed scheme: "unix"                         module=grpc
INFO[2020-09-26T15:11:03.919779317+03:00] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-09-26T15:11:03.919792653+03:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-09-26T15:11:03.919798154+03:00] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2020-09-26T15:11:03.920399082+03:00] parsed scheme: "unix"                         module=grpc
INFO[2020-09-26T15:11:03.920409757+03:00] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-09-26T15:11:03.920418642+03:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-09-26T15:11:03.920423441+03:00] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2020-09-26T15:11:04.050458554+03:00] [graphdriver] using prior storage driver: overlay2 
WARN[2020-09-26T15:11:04.212728085+03:00] Your kernel does not support swap memory limit 
WARN[2020-09-26T15:11:04.212780116+03:00] Your kernel does not support cgroup rt period 
WARN[2020-09-26T15:11:04.212798165+03:00] Your kernel does not support cgroup rt runtime 
WARN[2020-09-26T15:11:04.212812782+03:00] Your kernel does not support cgroup blkio weight 
WARN[2020-09-26T15:11:04.212830211+03:00] Your kernel does not support cgroup blkio weight_device 
INFO[2020-09-26T15:11:04.213206856+03:00] Loading containers: start.                   
INFO[2020-09-26T15:11:04.547434099+03:00] Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address 
INFO[2020-09-26T15:11:04.985878757+03:00] Loading containers: done.                    
INFO[2020-09-26T15:11:05.259805773+03:00] Docker daemon                                 commit=4484c46d9d graphdriver(s)=overlay2 version=19.03.13
INFO[2020-09-26T15:11:05.259975115+03:00] Daemon has completed initialization          
INFO[2020-09-26T15:11:05.418371093+03:00] API listen on /var/run/docker.sock           

但是再次运行dockerfile会导致相同的错误。我很不知道为什么会发生这种情况,所以我希望得到任何反馈。

如果需要更多信息,请告诉我,我很乐意提供。提前感谢:)

共有3个答案

阳博赡
2023-03-14

如果其他建议没有帮助,只需重新启动电脑/笔记本电脑即可。它帮助了我:)

盖辉
2023-03-14

为了流行音乐_操作系统用户:

如果您通过PoP安装了PyCharm/PhpStorm/IntelliJ_选购扁平封装图片:

flatpak override --user --filesystem=/run/docker.sock com.jetbrains.PyCharm-Community

根据使用的版本/口味更改尾随的jet大脑产品名称(此处:PyCharm-Community)。

乔俊才
2023-03-14

您是否可以在不使用sudo的情况下运行docker命令,如docker images?如果没有,则应运行sudo usermod-aG docker$USER,然后可以作为非root用户使用命令(https://docs.docker.com/engine/install/linux-postinstall/). 我不确定这是否能解决你的问题。

 类似资料: