787

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

but it gives the error:

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

21
  • If you run ps aux | grep docker, do you see the daemon process running? Jun 21, 2017 at 14:21
  • Possible duplicate: stackoverflow.com/questions/21871479/…
    – BMitch
    Jun 21, 2017 at 14:22
  • 1
    @Rome_Leader see the output in my question ...
    – Umair Ayub
    Jun 21, 2017 at 14:22
  • 23
    try this : sudo service docker restart Jun 21, 2017 at 14:23
  • 11
    you can see the status of you docker deamon using this : sudo service docker status check if it is active Jun 21, 2017 at 14:25

63 Answers 63

547

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
11
  • 32
    Running first command, I got an error: Failed to start docker.service: Unit docker.service is masked. So, I had to run following: systemctl unmask docker.service systemctl unmask docker.socket systemctl start docker.service
    – Chinh Phan
    Jul 26, 2018 at 3:26
  • 39
    sudo service docker start * Starting Docker: docker was the fix for me. Aug 17, 2021 at 20:42
  • 8
    Neither systemctl start docker nor sudo service docker start worked for me, on Ubuntu 22.04 -- I still get the same error message.
    – Raleigh L.
    Oct 25, 2022 at 23:29
  • 11
    When I ran systemctl start docker I got System has not been booted with systemd as init system (PID 1). Can't operate..
    – John Jiang
    Oct 29, 2022 at 23:43
  • 4
    This is due to the fact that you're trying to run this command in a distro (or an alpine container, for example) that does not use systemd as a "process manager". systemctl is a command from systemd, so that does not work. What's your environnement ?
    – H.Gmz
    Dec 12, 2022 at 9:18
376

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.

16
  • 11
    It gives me error Error starting daemon: Devices cgroup isn't mounted Jun 26, 2019 at 14:42
  • 2
    Thanks, it worked form me! Also @fepegar told that the installation can be not OK. How I would repair it? Dec 2, 2020 at 11:50
  • 26
    Worked for me on the wsl2 running Ubuntu too. Apr 13, 2021 at 16:08
  • 5
    Thanks! This gave me a lot more info and the actual error of why docker wasn't starting: failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain, which I was able to solve by switching iptables to nftables in my Debian. Oct 14, 2021 at 9:22
  • 7
    it also helped me in wsl2 Dec 22, 2021 at 16:27
121

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
2
  • 3
    I don't think a second sudo service docker start is necessary. First 2 lines were enough for me. Can you edit your answer? Mar 8, 2022 at 15:09
  • 15
    this has worked for me. in wsl2 May 17, 2022 at 7:41
80

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.

1
  • 4
    How can I prevent this from happening? Every time I turn on my PC, I have to remove docker.pid!
    – Hamidreza
    Jul 18, 2020 at 8:41
77

Easy way to fix this issue, try this

sudo su
systemctl start docker
systemctl enable docker
systemctl restart docker

or

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl restart docker
3
  • 4
    systemctl restart docker
    – M.Hefny
    Dec 1, 2020 at 19:01
  • 4
    don't forget to do it with god rights, aka 'root' user: sudo su Mar 30, 2021 at 11:43
  • You don't need to both start and restart. Just enable and restart then. Mar 14 at 8:18
47

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.

5
  • It worked for me as well I forgot to run the Docker Desktop on my mac. Thank you Aug 1, 2021 at 17:47
  • 1
    This worked for me as a mac m1 user. But I am curious why did it start working after opening docker desktop ? Is there some pre-defined configuration which enables/starts docker engine running ? Jun 10, 2022 at 3:42
  • I believe there is demon process init when the docker desk running
    – Ping Woo
    Aug 2, 2022 at 2:39
  • After about 20 mins of trying to figure out what was wrong, turns out I just forgot to start Docker Desktop. This helped a lot, thank you.
    – Ochuko
    Apr 16 at 20:40
  • Note that OP was asking about Linux, not Mac. The path mentioned in the question was never used on a Mac... Jun 5 at 23:05
43

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.

8
  • 1
    running sudo nohup docker daemon -H http://tcp://0.0.0.0:2375 () -H http://unix:///var/run/docker.sock gives bash: syntax error near unexpected token ('`
    – Umair Ayub
    Jun 21, 2017 at 18:52
  • 1
    I am running redhat linux
    – Umair Ayub
    Jun 21, 2017 at 18:52
  • ohh... sorry. Extra chars (), updated. Which version of RHEL ? Simply check what value you get with $DOCKER_HOST ?
    – mohan08p
    Jun 22, 2017 at 6:36
  • 3
    Warning to anyone following this advice, -H tcp://0.0.0.0:2375 exposes an unencrypted root login over the network without any password.
    – BMitch
    Sep 12, 2018 at 22:34
  • 1
    I saw docker not starting because of not enough space.
    – prayagupa
    Apr 23, 2021 at 19:13
32

Ubuntu 22.04 is my operating system. After conducting extensive research and browsing numerous websites, I discovered that running Docker as a non-root user creates a different context. My problem was resolved by using the commands listed below.

docker context ls 
docker context use default 
6
  • 3
    This was what did it for me on Pop OS 22.04.
    – Kyle
    Jan 9 at 21:06
  • 2
    this is the only solution worked for me, 2023, ubuntu20
    – Danish
    Jan 18 at 14:33
  • 1
    Hours. Hours and hours and hours, before I stumbled on this answer. Thank you, sincerely. Pop OS 22.04 here as well, March 2023. THIS was the answer. I'd somehow created and locked docker into a different "context" in my home folder. (Re)setting it to default fixed it. Thank you thank you thank you
    – Inigo
    Mar 23 at 11:38
  • 1
    works on fedora too Apr 24 at 15:05
  • I also use ubuntu 22.04, after days and days of research, this is the only one that worked for me. i wished i could double vote this. Thanks a lot. Jul 6 at 7:23
31

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

0
27

It's worked for me:

sudo systemctl unmask docker
sudo systemctl start docker
2
  • what does it do? Dec 2, 2020 at 15:41
  • @DJ_Stuffy_K Masking a service prevents the service from being started manually or automatically, which is a stronger version of disable. Masking disables all symlinks of the specified unit file are removed. For more details Dec 3, 2020 at 5:21
23

This works fine for me..!

service docker restart
1
  • For some reason, even though I ran this command earlier (and it didn't work at that time), for some reason something else I did while going through the answers on this list led to this command suddenly working for me. Here is subset of the commands I ran in-between the failing and working invocations of service docker restart: service docker stop, service docker start, docker context use default, systemctl stop docker, systemctl stop docker.socket. One or more of those may have caused a subsequence service docker restart to work, and docker run hello-world succeeded.
    – pnkfelix
    Dec 12, 2022 at 21:33
19

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

sudo /etc/init.d/docker start
2
  • It is true for WSL on windows 10. Jan 18, 2021 at 17:52
  • top. worked for me. thanks.; Nov 5, 2021 at 20:56
19

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

3
  • 1
    I had to do it with Sudo on a Ubuntu 18.04
    – Basanth
    Jul 20, 2020 at 16:02
  • Thank you for that. Glad to be able to find such a simple fix
    – FARS
    Mar 16, 2022 at 7:27
  • The only option that helped me on Ubuntu 20.04. May 3 at 13:40
15

On Ubuntu 22 "sudo service docker start" worked for me.

vikaspiprade@AUMEL-P7750-VP:~$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at 
unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
vikaspiprade@AUMEL-P7750-VP:~$ sudo /var/run/docker.sock
sudo: /var/run/docker.sock: command not found
vikaspiprade@AUMEL-P7750-VP:~$ /var/run/docker.sock
-bash: /var/run/docker.sock: Permission denied
vikaspiprade@AUMEL-P7750-VP:~$ sudo service docker stop
* Docker already stopped - file /var/run/docker-ssd.pid not found.
vikaspiprade@AUMEL-P7750-VP:~$ sudo service docker start
* Starting Docker: docker                                                                                       
[ OK ]
vikaspiprade@AUMEL-P7750-VP:~$

enter image description here

11

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

0
11

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

1
  • I have no idea why this works, but it worked for me on WSL. Jul 12, 2022 at 9:38
9

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

service docker start

export DOCKER_HOST="tcp://0.0.0.0:2375"
1
  • 3
    If this works on your host, then you effectively have no root password. Anyone with access to that port can run commands as root on your host.
    – BMitch
    May 14, 2019 at 20:27
7

here's the solution which works for me on Linux

systemctl start docker.

2
  • For Ubuntu WSL on windows use - sudo service docker start May 15, 2021 at 14:28
  • "Failed to start docker..service: Unit docker..service not found."
    – Reza Taba
    Aug 8, 2021 at 21:53
7

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
7

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

Or, if $USER contains your user's name:

 sudo  chown $USER:$USER /var/run/docker.sock
2
  • It worked for me without needing to add the volumes May 6, 2022 at 21:49
  • hello, i am new to the docker and tried to run docker run hello-world and encountered with this problem. Can you please tell me where i find the volume and add those? Thank you
    – Ada
    Jul 24, 2022 at 10:45
6

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
4
  • Hi @ukaliko, did you install "Docker Desktop" on windows? this instruction : docs.docker.com/engine/install/ubuntu/#installation-methods does not mention the "docker desktop" Sep 6, 2020 at 14:08
  • Hi @ukaliko, I decided to install the "docker desktop" on windows. and now all works. maybe in the future i will try to upgrade WSL to WSL2 and see if i can avoid the unsafe tcp 2375 port thing. Sep 6, 2020 at 14:57
  • 1
    just a small comment @ukaliko, sudo usermod -aG docker $ USER, you had a space between $ and USER Sep 8, 2020 at 9:09
  • Thanks for letting me know soMuchToLearnAndShare , here's the tip guys. soMuchToLearnAndShare sorry I just saw your comment. But I'm glad that everything worked! Show!...Vlw soMuchToLearnAndShare. Strong hug!
    – ukaliko
    Aug 26, 2021 at 23:18
6

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

2
  • the solution is awesome
    – Mo.
    Feb 21, 2022 at 15:34
  • upvote please :)
    – Kaushik J
    Feb 22, 2022 at 16:59
5

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.

4

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

3
  • great answer! THANKS! Sep 3, 2020 at 12:43
  • also make sure the content in the .json file is a valid JSON :-) (you may forget to put {} around partial config, ,comma at the end etc...
    – jave.web
    Mar 16 at 11:42
  • A very obscure cause - invalid daemon.json! You can spot this by doing sudo journalctl -u docker.service and then G (to go to end). You'll see entries likeJul 23 16:38:14 someSystemName dockerd[2192]: time="2023-07-23T16:38:14.306020907-04:00" level=error msg="Error writing log message" driver=json-file error="error writing log entry: write /var/lib/docker/containers/39571f0b7e97a496a5b24ddd One possible cause for this is when you paste a daemon.json from a web site or word doc and the character formatting is not quite right. Just retype everything to make sure you're good.
    – James_SO
    Sep 8 at 0:32
4

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.

1
  • The only thing that worked for me!!! Thanks Dec 13, 2021 at 4:53
4

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.

1
  • 1
    This was exactly the problem for me.
    – MAPK
    Nov 30, 2021 at 21:08
4

This works in my case:

sudo service docker start
4

In WSL, running dockerd solve the issue.

$ sudo dockerd
3

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.
1
  • Restarting the docker desktop worked for me.Thanks Sep 20, 2021 at 6:20
3

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.