Cyberithub

Solved "Error while dialing dial unix /var/run/dockershim.sock"

Advertisements

In this article, we will see how to solve error while dialing dial unix /var/run/dockershim.sock if you are also facing this error in your system. Sometimes you may have noticed that whenever you try to use crictl container runtime interface CLI then you always end up with some error, the error while dialing dial unix /var/run/dockershim.sock is also one of them. This error mostly comes when you try to use it for the very first time in your system. This made me write an article about this error before solving the problem so that it will help you folks as well in understanding and solving the error. So without further delay, let's look at my use case scenario.

 

Solved "Error while dialing dial unix /var/run/dockershim.sock"

Solved "Error while dialing dial unix /var/run/dockershim.sock"

Also Read: How to Install Snyk CLI with NPM or YARN on Ubuntu/Debian

So as I stated earlier, in my case I have been trying to use crictl container runtime interface CLI to list out the images but all I received on the output is the error while dialing dial unix /var/run/dockershim.sock as you can also see below.

NOTE:

Please note that Dockershim has been removed from the Kubernetes project as of release 1.24. More on official website.
[cyberithub@centos ~]$ crictl images
DEBU[0000] get image connection
DEBU[0000] ListImagesRequest: &ListImagesRequest{Filter:&ImageFilter{Image:&ImageSpec{Image:,Annotations:map[string]string{},},},}
E0415 18:55:23.725129 8390 remote_image.go:119] "ListImages with filter from image service failed" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory\"" filter="&ImageFilter{Image:&ImageSpec{Image:,Annotations:map[string]string{},},}"
FATA[0000] listing images: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory"

Before fixing above error, you need to first check the currently installed container runtime in your System by using kubectl get nodes -o wide command as shown below.

[cyberithub@centos ~]$ kubectl get nodes -o wide
NAME       STATUS  ROLES                AGE   VERSION INTERNAL-IP  EXTERNAL-IP OS-IMAGE              KERNEL-VERSION    CONTAINER-RUNTIME
centos     Ready   control-plane,master 8m13s v1.20.1 192.168.0.18 <none>      CentOS Linux 7 (Core) 4.4.0-210-generic containerd://1.5.1
node1      Ready   <none>               90s   v1.20.1 192.168.0.17 <none>      CentOS Linux 7 (Core) 4.4.0-210-generic containerd://1.5.1

As you can see from above, it is containerd runtime in our case. So the error is simply because I have configured dockershim endpoint to be used in crictl configuration which I don't have in my local system. So to fix the above error, I reconfigured crictl endpoint to use containerd runtime instead of dockershim using below command.

[cyberithub@centos ~]$ echo "===================================" &&\
> echo "Config BEFORE change:" &&\
> sudo cat /etc/crictl.yaml &&\
> sudo crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock --set image-endpoint=unix:///run/containerd/containerd.sock &&\
> echo "===================================" &&\
> echo "Config AFTER change:" &&\
> sudo cat /etc/crictl.yaml
===================================
Config BEFORE change:
runtime-endpoint: unix:///var/run/dockershim.sock
image-endpoint: unix:///var/run/dockershim.sock
timeout: 2
debug: true
pull-image-on-create: false
disable-pull-on-run: false
===================================
Config AFTER change:
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 2
debug: true
pull-image-on-create: false
disable-pull-on-run: false

After running above command, I tried listing the images again by using crictl images command and guess what, this time it ran successfully.

NOTE:

You may notice that this time I am running crictl images command with sudo access. This is simply because you might get permission denied error even after solving the original error in case you don't have enough privileges to access the images, just like in my case. So I had to run below command with sudo access.
[cyberithub@centos ~]$ sudo crictl images
DEBU[0000] get image connection
DEBU[0000] ListImagesRequest: &ListImagesRequest{Filter:&ImageFilter{Image:&ImageSpec{Image:,Annotations:map[string]string{},},},}
DEBU[0000] ListImagesResponse: &ListImagesResponse{Images:[]*Image{},}
IMAGE  TAG   IMAGE   ID     SIZE
................................................

Above output indicates that the error while dialing dial unix /var/run/dockershim.sock is now resolved and we are now able to use crictl container runtime interface cli. Sometimes, it may also be possible that you are using the correct container runtime but still you are getting the same error. In those cases, I would suggest you to restart the container runtime service once and see if this resolve your error. For example, if you are using containerd runtime then you can use sudo systemctl restart containerd command to restart the service as shown below.

[cyberithub@centos ~]$ sudo systemctl restart containerd

Hope, above given solution should be enough to solve your error as well. But in case if you are still not able to resolve the error then please let me know in the comment box so that I can take a look and see if I can help.

Leave a Comment