11

I am new to docker and haven't found a question here to answer the problem I'm experiencing.

I am tryin to use Pycharm to run a dockerfile, in order to debug certain program inside the docker. I opened the dockerfile in pycharm, and I created a configuration for running the dockerfile. Running the program results in an error message under the 'services' tab:

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

After I Googled the problem, I found this thread: Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?

Which said I should be running sudo dockerd. After some bugs I uninstalled docker completely, and installed it again. After installation I ran:

systemctl status docker

And the output is:

● 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

So I stopped it using sudo service docker stop I ran systemctl status docker again and it was indeed stopped:

● 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.

So I ran sudo dockerd and it seemed to run fine:

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           

But running the dockerfile again resulted in the same error. Im quite at a loss as to why this happens, so I would appreciate any feedback.

Should more information be needed, let me know and I'll be happy to provide. Thanks in advance :)

yonatansc97
  • 584
  • 6
  • 16

6 Answers6

13

In Docker desktop application on my Mac, under Settings->Advanced I had to enable Enable default Docker socket (Requires password) option, after that connection from PyCharm worked.

Mark Kuhar
  • 131
  • 1
  • 2
  • I had the same problem in PHPStorm and this fixed it. I guess that setting was changed in a recent Docker Desktop update. – Don't Panic Jun 13 '23 at 18:01
12

Can you run docker command such as docker images without sudo? If not, you should run sudo usermod -aG docker $USER and then you can use docker command as non-root user (https://docs.docker.com/engine/install/linux-postinstall/). I'm not sure if it will solve your problem.

Rui
  • 447
  • 4
  • 9
  • Hi Rui, I ran the command, but when I try without sudo, I get permission denied error. Do you think it would have solved the problem? It sounds to me like a different probelm. – yonatansc97 Sep 26 '20 at 15:16
  • 1
    That means you cannot run docker command as non-sudo user. I guess maybe you run Pycharm as non-root user and have the above problem. So I suggest to run `sudo usermod -aG docker $USER` commend. It can solve the 'non-root' problem and may solve your original one. – Rui Sep 27 '20 at 00:14
  • What I meant by my last comment is that even afte running "sudo usermod ...", it doesn't seem to work. But today as a last attempt I ran it and is worked fine. Thank you very much @Rui! – yonatansc97 Sep 27 '20 at 05:20
  • 7
    You also have to login and logout of linux to make the changes take effect – Tom Dec 20 '20 at 15:23
  • This, combined with logging out and back in, fixed my instance of this error. – Jessime Kirk Dec 12 '22 at 01:59
9

For flatpack users - tested on Pop!_OS:

If you installed PyCharm / PhpStorm / IntelliJ as flatpack image (e.g. via PoP!_Shop):

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

Change the trailing jetbrains product name (here:PyCharm-Community) according to the used version / flavour.

nash0rn
  • 271
  • 4
  • 5
2

My problem was the following:

I want to setup debugger in container, but pycharm can't connect to docker daemon.

My environment was: Ubuntu 22.04 PyCharm professional Docker Engine v23.0.5

I can run docker commands without sudo, but when try to connect pycharm with docker - have same error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

So it was pretty easy, I choose docker-desktop in connection menu and ran docker desktop

0

Just restart the computer/laptop if other suggestions did not help. It helped me :)

Sofiia
  • 19
  • 1
0

before i installed Pycharm by flatpak from Discover (i use KDE Linux, Discover same like Software Update In Ubuntu). It is main reasion. And then i reinstall Pycharm by tar file in home page of Pycharm. It work for me.