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

LinuxUbuntuDockerUbuntu 14.04

Linux Problem Overview


I have applied every solution available on internet but still I cannot run Docker.

I want to use Scrapy Splash on my server.

Here is history of commands I ran.

docker run -p 8050:8050 scrapinghub/splash
sudo docker run -p 8050:8050 scrapinghub/splash
sudo usermod -aG docker $(whoami)
sudo docker run -p 8050:8050 scrapinghub/splash
newgrp docker
sudo docker run -p 8050:8050 scrapinghub/splash
reboot
sudo docker run -p 8050:8050 scrapinghub/splash
docker run -p 8050:8050 scrapinghub/splash

You can see I tried to restart my server as well, but it didnt help.

see output of ps -aux | grep docker

root@mani:/var/www/html# ps aux | grep docker
root      8524  0.0  0.8 127904 13964 ?        Ssl  17:21   0:00 /usr/bin/dockerd --raw-logs
root      8534  0.0  0.3  90588  5012 ?        Ssl  17:21   0:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
root      8543  0.0  0.0   8812   764 pts/1    S+   17:21   0:00 grep --color=auto docker
root     16356  0.0  0.0  17200   964 pts/1    S    17:14   0:00 newgrp docker
root     20080  0.0  0.0  17200   964 pts/1    S    17:06   0:00 newgrp docker
root     30221  0.0  0.0  17200   964 pts/1    S    17:09   0:00 newgrp docker

Linux Solutions


Solution 1 - Linux

You can try out this:

systemctl start docker

It worked fine for me.

P.S.: after if there is commands that you can't do without sudo, try this:

gpasswd -a $USER docker

Solution 2 - Linux

Just Run

sudo dockerd

dockerd is the daemon service for docker containers, because it is not running in background we're not able to take any actions related to the service, which needs be restarted.

Solution 3 - Linux

You can get this error if docker doesn't shut down cleanly. The following answer is for the docker snap package.

Run snap logs docker and look for the following:

Error starting daemon: pid file found, ensure docker is not running or delete /var/snap/docker/179/run/docker.pid

Deleting that file and restarting docker worked for me.

rm /var/snap/docker/<your-version-number>/run/docker.pid
snap stop docker
snap start docker

Make sure to replace ‍‍‍‍<your-version-number>‍ with the appropriate version number.

Solution 4 - Linux

I just hit this after doing a fresh install of DOCKER from the main docs. The problem for me was that immediately after the install, the service is not running.

These commands will help you to make sure docker is up and running for your run command to find it:

$ sudo service --status-all 
$ sudo service docker start
$ sudo service docker start

Solution 5 - Linux

Easy way to fix this issue, try this

sudo su
systemctl start docker
systemctl enable docker
systemctl restart docker

Solution 6 - Linux

First, try with sudo, as the current user may not have access permissions to communicate to docker daemon i.e.:

/var/run/docker.sock

If its still not working, then, after the installation, simply stop the docker daemon:

sudo service docker stop

And, run the following command to start the daemon in background:

sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

To make working with Docker easier, you should add your username to the Docker users group. Adding a user to the group can be done with the command below:

sudo usermod -aG docker $USER

Also, this step is mentioned in the official documentation of docker Post-installation steps for Linux.

Ubuntu 16.04 users can follow these steps:

Inside file /lib/systemd/system/docker.service change:

ExecStart=/usr/bin/dockerd fd://

to

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375

Inside file /etc/init.d/docker change:

DOCKER_OPTS=

to

DOCKER_OPTS="-H tcp://0.0.0.0:2375"

and then restart your machine, and start playing with docker.

Solution 7 - Linux

enter image description here

I just simply forget running the Docker Desktop in my mac, after running Docker Desktop, you will be good to go.

Solution 8 - Linux

This usually happened if you haven't stopped docker probably.

To resolve

service docker stop
cd /var/run/docker/libcontainerd
rm -rf containerd/*
rm -f docker-containerd.pid
service docker start

then "docker run...." to download your image and start the container as usual

Solution 9 - Linux

It's worked for me:

sudo systemctl unmask docker
sudo systemctl start docker

Solution 10 - Linux

I guess if you are using WSL with GUI, then you could just try

sudo /etc/init.d/docker start

Solution 11 - Linux

I had this problem after closing docker while pulling a container:

docker pull mongo

At first I was getting weird errors so I purged docker:

sudo apt-get purge docker.io

and reinstalled:

sudo apt-get install docker.io

All of this did nothing; I couldn't even run the "hello-world" container.

The correct fix, for me at least was:

systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

After this I could pull mongo and run "hello world".

Solution 12 - Linux

This works fine for me..!

service docker restart

Solution 13 - Linux

I'm running on root and tried below, it worked:

service docker start

export DOCKER_HOST="tcp://0.0.0.0:2375"

Solution 14 - Linux

It happens by the docker is not started yet.

Please check the docker status

$ sudo systemctl status docker

Then start and enable the docker and recheck the status

$ sudo systemctl start docker && sudo systemctl enable docker && sudo systemctl status docker

Thats it. Now the last step for checking the docker is working fine

$ sudo docker run hello-world

Solution 15 - Linux

On Ubuntu 20.04 and Docker version 20.10.11,as a non root user, Running:

sudo service docker start

Then checking the status

sudo service docker status

Shows

* Docker is running

But trying any docker command such as

docker images

Shows the same error

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

Running the below solves it

sudo service docker restart

Restart solved it, while start did not

Solution 16 - Linux

here's the solution which works for me on Linux

systemctl start docker.

Solution 17 - Linux

I also received the error message below, after installing the docker and running: docker run hello-world #Cannot connect to the Docker daemon at unix: /var/run/docker.sock. Is the docker daemon running?

Here's a solution, what worked for me. Environment

  • Windows 10 (Don't forget to enable on windows: Settings> Update and Security> Developer mode)
  • Ubuntu 18.04 LTS
  • Docker Desktop version 2.3.0.2 (45183)
    • Enable in Docker Desktop: Expose daemon on tcp: // localhost: 2375 without TLS
    • Docker Desktop must also be running (connected to Docker Hub ... just log in)

After installing ubuntu, update the repository

sudo apt-get update

To use a repository over HTTPS

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Add the official Docker GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Make sure you now have the key with the fingerprint

sudo apt-key fingerprint 0EBFCD88

Update the repository

sudo apt-get update

Update the docker repository

sudo add-apt-repository "deb [arch = amd64] https://download.docker.com/linux/ubuntu $ (lsb_release -cs) stable "

Update the repository again

sudo apt-get update

Command to install the docker in version: 5: 18.09.9 ~ 3-0 ~ ubuntu-bionic

sudo apt-get install docker-ce = 5: 18.09.9 ~ 3-0 ~ ubuntu-bionic docker-ce-cli = 5: 18.09.9 ~ 3-0 ~ ubuntu-bionic containerd.io

Command to set the DOCKER_HOST

export DOCKER_HOST="tcp://0.0.0.0:2375"

Note: put the command above in your profile to start with the ubunto ex: echo "export DOCKER_HOST="tcp://0.0.0.0:2375"" >> ~/.bashrc

Add user to the docker group

sudo usermod -aG docker $USER

Restart ubuntu

(Close and open the ubuntu window again) or run:

source ~/.bashrc

Testing the installation (DO NOT use more sudo before docker commands (it will give an error), the user "root" has already been included in the docker group)

docker run hello-world

The message below should be displayed

Hello from Docker! This message shows that your installation appears to be working correctly.

Note: if it fails, run the command again:

export DOCKER_HOST="tcp://0.0.0.0:2375"

Reference: https://docs.docker.com/engine/install/ubuntu/ Session: INSTALL DOCKER ENGINE

#For other versions of the docker that can be installed with ubuntu, see the repository using the command below: apt-cache madison docker-ce

Then install the desired version of the docker:

sudo apt-get install docker-ce = <VERSION_STRING> docker-ce-cli = <VERSION_STRING> containerd.io

Solution 18 - Linux

Make sure information in this path /etc/docker/daemon.json

{
  "registry-mirror": [
    "https://registry.docker-cn.com"
  ],
  "insecure-registries": [
    "192.168.199.100:5000"
  ]
}

delete

"insecure-registries": [
    "192.168.199.100:5000"
]

and runs well enter image description here

Solution 19 - Linux

I installed docker from snap repository. So I also had to start from snap (running Ubuntu).

sudo snap start docker

Otherwise you can also install it from their repositories.

Solution 20 - Linux

if you are using MAC so just type docker in finder it will automatically resolve.

Solution 21 - Linux

2022 Solution

This work by my side:

Add the below in your volume:

volumes:
 - "/var/run/docker.sock:/var/run/docker.sock"

after that execute the below command

 sudo  chown 1000:1000 /var/run/docker.sock

Please note 1000 is the ID of the user. to know it execute the below command:

id

Solution 22 - Linux

I was trying to run docker(just installed) in an instance of AWS when the message appears. I just write sudo service docker start and works fine for me.

Also see AWS with Docker

Solution 23 - Linux

This exception comes when the service of docker is not running or the logged in user dont have the permission to access docker and generally it comes in RedHat

Using below command should resolve the issue

>>> sudo service docker start

enter image description here

Solution 24 - Linux

for linux run

sudo dockerd

However, if you use Docker Client for mac it won't work. try the below code

$socat TCP-LISTEN:2376,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock

https://forums.docker.com/t/using-pycharm-docker-plugin-with-docker-beta/8617/9

That workaround opens port 2376 to the world... as TLS isn't enabled, this is a bad idea as anyone on the same network can hijack your docker daemon

Solution 25 - Linux

I had the same problem for gitlab CI running node:lts image:

  • I just restarted the docker daemon and restart the container, it worked for me.

Solution 26 - Linux

use this in ubuntu export DOCKER_HOST=tcp://localhost:2375

Solution 27 - Linux

export DOCKER_HOST=tcp://localhost:2375 is perfect for anyone who doesn't have sudo access and the user doesn't have access to unix:///var/run/docker.sock

Solution 28 - Linux

None of the current answers worked for my version of this error. I'm using the desktop version of Ubuntu 18. The following two commands fixed the issue.

sudo snap connect docker:home :home

sudo snap start docker

Solution 29 - Linux

In root mode, run the command systemctl start docker

And afterwards, you can check the status by running systemctl status docker

Solution 30 - Linux

I had this problem when docker was started after my terminal was started. Restarting the terminal or the process hosting the terminal (such as vscode) resolved the issue.

Solution 31 - Linux

If you are trying to install docker with wsl 2 linux subsystem in windows, please read this document and check whether this command is executed:

wsl.exe --set-version (distro name) 2

and also check in your Windows OS docker->settings->Resources->Enable integration with additional distros: are checked on and restarted.

Solution 32 - Linux

I faced same issue on Linux when I installed docker using yum (yum install docker).

Resolution: download docker binary from official site: docker install, unpack and follow the installation steps.

Solution 33 - Linux

It could be related to no disk space left on the hard drive. Make sure you have space left on the device, Docker can't start up if there isn't any space left.

Solution 34 - Linux

This might be a bit late for you but hope it will help someone find their way through the docker jungles. The problem might be coming from a tcp port binding issue verify if this file exists

> /etc/systemd/system/docker.service.d

this is the default UNIX socket listening override file. The file might actauly be empty, but i find that the fact that it exists sometimes causes some headaches like what you faced. if it exists 1. then 2. if not just go straight to 2.

1. $ sudo rm -rf /etc/systemd/system/docker.service.d

2. $ sudo systemctl deamon-reload

I find that some of the recommendations here overlook the error being in the actual daemon failing to load

A good friend when playing with docker is

$ systemctl status docker.service

Solution 35 - Linux

For those fresh installing & trying to running docker on RaspberryPi (RPi) like me, I needed to reboot my RPi 4B+ to resolve this issue and actually run the docker daemon.

By the time of writing this contribution this great manual does mention the necessity to reboot RPi, but only after setting "Non root-user to the Docker Group".

HTH, should someone miss this like me..

Solution 36 - Linux

This worked for me, It might just work for you if you are using Ubuntu 16 or 18 (14 may also work). Easy to give a try:

Go to Ubuntu Software, type in Docker. Uninstall docker (108 mb) if it is preinstalled there. Install docker Now run the commands and see if the same error comes

The error:

enter image description here

After doing the above steps. enter image description here

As you can see, it worked:)

Solution 37 - Linux

For me the solution was to simply make sure I had installed the correct Docker package. For example, for Ubuntu the depreciated packages are:

  • docker
  • docker-engine
  • docker.io
  • containerd
  • runc

For installation check https://docs.docker.com. Instructions are provided for Ubuntu, CentOS, Debian and Fedora at the time of writing.

Solution 38 - Linux

For everyone who is having problems with Docker at the time of installation.

An error pointing to a failure in the docker service, do the commands below.

$ sudo apt update

$ sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

$ sudo apt update

$ apt-cache policy docker-ce

$ sudo apt install docker-ce

Solution 39 - Linux

I had the same issue. In my case, VPN was the culprit. Turning off the VPN helped with the successful installation.

Solution 40 - Linux

Just adding to the knowledge base. I found this video helpful. I do not have DOCKER_HOST defined. I do have a /etc/wsl.conf that has:

[automount]
root = /
options = "metadata"

After Restarting a few times docker hello-world worked.

Solution 41 - Linux

I didn't see this solution mentioned, so I'll post it in case it might help someone. I was running into this error on my MacOS machine. The reason was that I had the DOCKER_HOST environment variable set in my dotfiles. Unsetting it through unset DOCKER_HOST did the trick. I found the tip in the official docker for Mac documentation: https://docs.docker.com/desktop/mac/troubleshoot/#workarounds-for-common-problems.

Solution 42 - Linux

This issue can be resolved permanently by running

  1. systemctl enable docker
  2. service docker start

Solution 43 - Linux

Use docker start <your_container_name>

Then connect to database by using mssql -u <yourUsername> -p <yourPassword>

If you get an error in the first step then the docker is running and go with the second step.

Note: I use Mac as my primary OS and this might be the same answer for Unix based OSs. If not! Sorry in advance.

Solution 44 - Linux

Just restarting the system worked for me. It might be a temporary issue

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUmair AyubView Question on Stackoverflow
Solution 1 - LinuxH.GmzView Answer on Stackoverflow
Solution 2 - LinuxYash PokarView Answer on Stackoverflow
Solution 3 - LinuxniklasView Answer on Stackoverflow
Solution 4 - LinuxPaul McDanielView Answer on Stackoverflow
Solution 5 - LinuxWillie ChengView Answer on Stackoverflow
Solution 6 - Linuxmohan08pView Answer on Stackoverflow
Solution 7 - LinuxPing WooView Answer on Stackoverflow
Solution 8 - LinuxInnocent AnigboView Answer on Stackoverflow
Solution 9 - LinuxRakibul IslamView Answer on Stackoverflow
Solution 10 - LinuxMemphis MengView Answer on Stackoverflow
Solution 11 - LinuxJonathan SaylorView Answer on Stackoverflow
Solution 12 - LinuxAugustine JoseView Answer on Stackoverflow
Solution 13 - Linuxuser11500628View Answer on Stackoverflow
Solution 14 - LinuxKarthikeyan GanesanView Answer on Stackoverflow
Solution 15 - LinuxDavid MwauraView Answer on Stackoverflow
Solution 16 - LinuxMohammad HeydariView Answer on Stackoverflow
Solution 17 - LinuxukalikoView Answer on Stackoverflow
Solution 18 - Linuxchao chenView Answer on Stackoverflow
Solution 19 - LinuxSir hennihauView Answer on Stackoverflow
Solution 20 - LinuxAmit KumarView Answer on Stackoverflow
Solution 21 - LinuxAbd AbughazalehView Answer on Stackoverflow
Solution 22 - LinuxdmarquinaView Answer on Stackoverflow
Solution 23 - LinuxSumit AroraView Answer on Stackoverflow
Solution 24 - LinuxKaushik JView Answer on Stackoverflow
Solution 25 - Linuxakshaymittal143View Answer on Stackoverflow
Solution 26 - LinuxYash KeshriView Answer on Stackoverflow
Solution 27 - LinuxMantas MarmaView Answer on Stackoverflow
Solution 28 - LinuxEricView Answer on Stackoverflow
Solution 29 - LinuxAdityaView Answer on Stackoverflow
Solution 30 - LinuxGaTechThomasView Answer on Stackoverflow
Solution 31 - LinuxUnniView Answer on Stackoverflow
Solution 32 - LinuxDenysView Answer on Stackoverflow
Solution 33 - LinuxbasickarlView Answer on Stackoverflow
Solution 34 - LinuxNgodzaView Answer on Stackoverflow
Solution 35 - LinuxSold OutView Answer on Stackoverflow
Solution 36 - LinuxAshish GuptaView Answer on Stackoverflow
Solution 37 - LinuxRikHView Answer on Stackoverflow
Solution 38 - LinuxHisham JavedView Answer on Stackoverflow
Solution 39 - LinuxMuhammad AbdullahView Answer on Stackoverflow
Solution 40 - LinuxRay TayekView Answer on Stackoverflow
Solution 41 - LinuxdeividView Answer on Stackoverflow
Solution 42 - LinuxJ V ReddyView Answer on Stackoverflow
Solution 43 - LinuxPavankumar ANView Answer on Stackoverflow
Solution 44 - LinuxHamdhan Azeez TView Answer on Stackoverflow