777

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
Umair Ayub
  • 19,358
  • 14
  • 72
  • 146

62 Answers62

537

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
Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
H.Gmz
  • 5,447
  • 1
  • 8
  • 4
  • 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 '18 at 03:26
  • If you got docker through snap, do `docker.help` And follow the steps. Refer to https://askubuntu.com/questions/977961/unit-docker-service-could-not-be-found#978012 – Oscar Acevedo Aug 01 '20 at 21:28
  • 39
    ```sudo service docker start * Starting Docker: docker``` was the fix for me. – Alejandro Armas Aug 17 '21 at 20:42
  • @AlejandroArmas suggestion worked for me too. – shary.sharath Nov 17 '21 at 08:25
  • 7
    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 '22 at 23:29
  • 10
    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 '22 at 23:43
  • 2
    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 '22 at 09:18
  • 1
    For this error using the WSL "When I ran systemctl start docker I got System has not been booted with systemd as init system (PID 1). Can't operate." I fixed by installing "https://github.com/microsoft/WSL/releases/download/1.0.3/Microsoft.WSL_1.0.3.0_x64_ARM64.msixbundle" From : https://github.com/microsoft/WSL/releases – Cesar Cisneros Jan 06 '23 at 23:18
  • **systemctl** doesn't work on MacBook. – AnonymousUser Jan 17 '23 at 06:40
  • @CesarCisneros thanks for mentioning that, helped me fix an issue I was struggling with – Muhammad Talal May 09 '23 at 11:57
  • For WSL *******UNDER DOCKER DESKTOP ******* Resources --> WSL Integration Enable integration with my default WSL distro and Enable integration with additional distros – Jacob Joy Jun 02 '23 at 09:26
371

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.

Yash Pokar
  • 4,939
  • 1
  • 12
  • 25
  • 11
    It gives me error `Error starting daemon: Devices cgroup isn't mounted` – Vineet 'DEVIN' Dev Jun 26 '19 at 14:42
  • @fepegar Possibly you're not having docker installed properly – Yash Pokar Oct 24 '19 at 09:43
  • @YashPokar indeed, I ended up reinstalling and now things work as expected. Thanks. – fepegar Oct 24 '19 at 15:09
  • Only command that works for me inside a docker container to start a docker container. Need it for codebuild, to create my own environment while building. :-) – We are Borg Jun 09 '20 at 05:34
  • I use Rasperry 3 B with debian 9 and get: `failed to mount overlay:no such device. aufs was not found in /proc/filesystems and again failed to mount overlay`. `apt install docker-compose` did not work, I followed [this](https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl) toutorial – Timo Oct 12 '20 at 17:52
  • 2
    Thanks, it worked form me! Also @fepegar told that the installation can be not OK. How I would repair it? – no-stale-reads Dec 02 '20 at 11:50
  • 25
    Worked for me on the wsl2 running Ubuntu too. – Eduardo Fernandes Apr 13 '21 at 16:08
  • 4
    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](https://forums.docker.com/t/failing-to-start-dockerd-failed-to-create-nat-chain-docker/78269/2). – Kevin Cruijssen Oct 14 '21 at 09:22
  • 7
    it also helped me in wsl2 – sari paisley Dec 22 '21 at 16:27
  • This works. Neither `sudo service docker start` nor `sudo service docker start` worked. but if you had previously run docker, first I had to stop docker using `sudo service docker stop` before running `sudo dockerd` – ewalel Mar 14 '22 at 06:00
  • `dockerd` gives `bash: dockerd: command not found`, and `sudo apt-get install dockerd` shows `E: Unable to locate package dockerd` – John Jiang Oct 29 '22 at 23:45
  • @JohnJiang which operating system you're using? – Yash Pokar Oct 30 '22 at 17:03
  • @YashPokar I am using ubuntu 18.04 – John Jiang Nov 01 '22 at 23:40
  • @JohnJiang could you try re-installing docker and then run – Yash Pokar Nov 04 '22 at 09:19
  • After this :sudo dockerd "INFO[2023-04-09T17:54:27.719475449+06:00] Starting up failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid" – farhanahmedhasan Apr 09 '23 at 11:56
  • 1
    it is working for my Linux enviroment within Windows(wsl2) Thanks – Rajib Aug 31 '23 at 12:00
119

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
Antoniossss
  • 31,590
  • 6
  • 57
  • 99
Paul McDaniel
  • 1,471
  • 1
  • 7
  • 6
79

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.

Hamidreza
  • 1,465
  • 12
  • 31
niklas
  • 899
  • 6
  • 6
76

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
Willie Cheng
  • 7,679
  • 13
  • 55
  • 68
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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ping Woo
  • 1,423
  • 15
  • 21
  • It worked for me as well I forgot to run the Docker Desktop on my mac. Thank you – Moureen Caroline Aug 01 '21 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 ? – Meet Zaveri Jun 10 '22 at 03:42
  • I believe there is demon process init when the docker desk running – Ping Woo Aug 02 '22 at 02: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. – deltanboi Apr 16 '23 at 20:40
  • Note that OP was asking about Linux, not Mac. The path mentioned in the question was never used on a Mac... – Alexis Wilke Jun 05 '23 at 23:05
42

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.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
mohan08p
  • 5,002
  • 1
  • 28
  • 36
  • 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 '17 at 18:52
  • 1
    I am running redhat linux – Umair Ayub Jun 21 '17 at 18:52
  • ohh... sorry. Extra chars (), updated. Which version of RHEL ? Simply check what value you get with $DOCKER_HOST ? – mohan08p Jun 22 '17 at 06:36
  • $ sudo systemctl enable docker to start the docker service at boot time. – mohan08p Jun 22 '17 at 06:42
  • I am now trying to install Docker on `CentOS Linux release 7.3.1611 (Core)` ... But now error is `Your Linux kernel version 2.6.32-042stab116.2 is not supported for running docker. Please upgrade your kernel to 3.10.0 or newer.` ... can i update the kernel using `yum update kernel` ... ???? question is, will it delete everything on my server? its a live servers with a website running on it, i dont want to mess it up. – Umair Ayub Jun 22 '17 at 07:57
  • Yes. It's true you require min kernel version 3.10.0 or newer... Yes, be careful, if it's container environment, you could lose everything... as the kernel is shared b/w the containers. But, if it's VM env you could possibly do it with some techniques... like migrating your production server.. etc. – mohan08p Jun 22 '17 at 12:50
  • 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 '18 at 22:34
  • 1
    I saw docker not starting because of not enough space. – prayagupa Apr 23 '21 at 19:13
30

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

Innocent Anigbo
  • 4,435
  • 1
  • 19
  • 19
29

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 
  • 3
    This was what did it for me on Pop OS 22.04. – Kyle Jan 09 '23 at 21:06
  • 2
    this is the only solution worked for me, 2023, ubuntu20 – Danish Jan 18 '23 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 '23 at 11:38
  • 1
    works on fedora too – patrik kings Apr 24 '23 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. – Abayomi Olowu Jul 06 '23 at 07:23
  • Worked for me on openSUSE Tumbleweed with Docker version 24.0.4-ce, build 4ffc61430bbe – 804b18f832fb419fb142 Jul 17 '23 at 22:02
27

It's worked for me:

sudo systemctl unmask docker
sudo systemctl start docker
Rakibul Islam
  • 954
  • 1
  • 14
  • 25
  • what does it do? – DJ_Stuffy_K Dec 02 '20 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](https://adeshsuryan.in/what-is-docker-mask-and-how-to-unmask-docker-service/) – Rakibul Islam Dec 03 '20 at 05:21
23

This works fine for me..!

service docker restart
pkamb
  • 33,281
  • 23
  • 160
  • 191
Augustine Jose
  • 1,235
  • 8
  • 8
  • 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 '22 at 21:33
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".

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Jonathan Saylor
  • 321
  • 2
  • 2
19

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

sudo /etc/init.d/docker start
Memphis Meng
  • 1,267
  • 2
  • 13
  • 34
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

Vikas Piprade
  • 272
  • 2
  • 7
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

David Mwaura
  • 129
  • 1
  • 4
10

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

Amit Kumar
  • 1,503
  • 14
  • 11
9

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

service docker start

export DOCKER_HOST="tcp://0.0.0.0:2375"
Talha
  • 524
  • 1
  • 6
  • 22
user11500628
  • 91
  • 1
  • 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 '19 at 20:27
7

here's the solution which works for me on Linux

systemctl start docker.

Mohammad Heydari
  • 3,933
  • 2
  • 26
  • 33
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
Karthikeyan Ganesan
  • 1,901
  • 20
  • 23
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
OldBuildingAndLoan
  • 2,801
  • 4
  • 32
  • 40
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
  • It worked for me without needing to add the volumes – Azimjon Ilkhomov May 06 '22 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 '22 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
Renier
  • 1,523
  • 4
  • 32
  • 60
ukaliko
  • 172
  • 2
  • 7
  • Hi @ukaliko, did you install "Docker Desktop" on windows? this instruction : https://docs.docker.com/engine/install/ubuntu/#installation-methods does not mention the "docker desktop" – soMuchToLearnAndShare Sep 06 '20 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. – soMuchToLearnAndShare Sep 06 '20 at 14:57
  • 1
    just a small comment @ukaliko, ```sudo usermod -aG docker $ USER```, you had a space between ```$``` and ```USER``` – soMuchToLearnAndShare Sep 08 '20 at 09: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 '21 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

Kaushik J
  • 962
  • 7
  • 17
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.

basickarl
  • 37,187
  • 64
  • 214
  • 335
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

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
chao chen
  • 41
  • 1
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.

Sir hennihau
  • 1,495
  • 4
  • 18
  • 31
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.

GaTechThomas
  • 5,421
  • 5
  • 43
  • 69
4

This works in my case:

sudo service docker start
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
aakash4dev
  • 774
  • 4
  • 13
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.
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

dmarquina
  • 3,728
  • 1
  • 28
  • 28
3

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

Sumit Arora
  • 101
  • 1
  • 1
  • 5
3

In root mode, run the command systemctl start docker

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

Eyad Arafat
  • 601
  • 8
  • 19
Aditya
  • 340
  • 2
  • 10
2

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

  • 1
    If this works on your system, then you effectively have no root password. Anyone with access to that port can run commands as root on the host. – BMitch May 14 '19 at 20:25
2

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

  • 2
    This is also useful for anyone that doesn't normally have root access but would like to easily become root on your host. Anyone with access to that port can run commands as root. – BMitch May 14 '19 at 20:28
  • @BMitch care to elaborate? – Fran Marzoa Aug 02 '19 at 10:50
  • 1
    @FranMarzoa from another user that you do not trust, or even another host, you can run any `docker run` command with the root user inside the container, privileged, with host namespaces on pid and network, and mounting the root filesystem ok the box. – BMitch Aug 02 '19 at 12:46
2

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

Eric
  • 795
  • 5
  • 21
2

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
Ngodza
  • 387
  • 3
  • 8
2

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.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Unni
  • 99
  • 1
  • 9
1

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.

Denys
  • 1,308
  • 12
  • 13
1

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

Sold Out
  • 1,321
  • 14
  • 34
1

I read through all the answers and didn't find anything close to my situation. In the end, the problem turned out to be that docker was installed twice on my system, once on snap, and another time through the convenience script. So, if anybody runs into this problem, make sure to check that docker isn't installed in multiple places because that can cause some really weird behavior.

Saiansh Singh
  • 583
  • 5
  • 16
  • Make sure to come back tomorrow and mark this as your answer! – RufusVS Aug 11 '22 at 01:06
  • Interesting... I do have it installed twice, I installed Docker manually in ubuntu and I can get it to work through the terminal, whereas in VSC the docker tools never freaking work – Conor Sep 07 '22 at 17:11
1

To me docker was really not running missing the following command to start it:

systemctl --user start docker-desktop
Valladão
  • 327
  • 4
  • 18
1

for me the cause of the error was docker desktop i had forced quit it . so restarting docker desktop worked for me and error got resolved .

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as code segment, commands or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – Rohit Lal Dec 12 '22 at 15:18
1

on windows 11 with ubuntu 22 the command wsl.exe --update in power shell helped me to run docker through containerd as it was on windows 10

before that i was getting Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running which wasn't happend to me on windows 10 ubuntu 20.04 with the same set up.

starting with ordinary sudo service docker start

Alexander
  • 47
  • 1
  • 2
  • 7
1

I had the same error with Rancher Desktop (v1.8.1) on MacOS with Intel Silicon. This issue happened right after installation. I did not change anything compared to the basic settings.

Turns out one needs to select dockerd as container engine instead of the default containerd in order to use docker from cli.

Settings in Rancher Desktop

I hope this helps somebody.

vargen_
  • 2,590
  • 3
  • 24
  • 30
1

I tried all the previous solutions and couldn't resolve my problem. Commands like systemctl and service were unknown to the command line.

That is when I thought about actually opening docker application, and get the whale icon on my menubar shown in my laptop. When I did, all the commands started working, and the error was gone too.

I just wanted to add this INCASE someone needs to see the obvious.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
1

If you download the Docker app, setup everything including your profile, and then keep it running while executing the command, it should work.

Sam
  • 105
  • 2
  • 11
0

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:)

Ashish Gupta
  • 65
  • 1
  • 8
0

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.

RikH
  • 2,994
  • 1
  • 16
  • 15
  • You missed some steps: follow this link for signing the repo. https://medium.com/@sebagomez/installing-the-docker-client-on-ubuntus-windows-subsystem-for-linux-612b392a44c4 – Robert Mar 27 '19 at 00:17
  • @Robert, above I also refer to the official docs.docker to get the PGP key. This is more secure than users copying it from this site or medium. – RikH Mar 27 '19 at 08:50
  • I tried the ubuntu steps and those are not working. Need the signing process and the link I provided. – Robert Mar 27 '19 at 12:51
  • @Robert, thanks I have removed my incomplete instructions and instead just refer to the official documentation. – RikH Mar 27 '19 at 13:20
0

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
Hisham Javed
  • 159
  • 2
  • 4
0

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.

Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
0

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.

deivid
  • 4,808
  • 2
  • 33
  • 38
0

I had this error message when I was not logged into Docker. Before more advanced troubleshooting, make sure you're logged into Docker. On mac, open the Docker Desktop app and sign in. This fixed the error for me.

blackholes
  • 11
  • 2
0

Docker.sock works as a channel to communicate between docker CLI and docker daemon. You can simply run your container by using this command.

docker run -v /var/run/docker.sock:/var/run/docker.sock  <ImageName>:latest
0

In my case when doing sudo dockerd --debug it showed this error: "failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found"

To solve it I put:

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
sudo systemctl start docker.service

For more details you can check: https://forums.docker.com/t/failing-to-start-dockerd-failed-to-create-nat-chain-docker/78269

Jaime Roman
  • 749
  • 1
  • 11
  • 26
0

Assign Ownership to the Docker Unix Socket

The “cannot connect to the Docker daemon” error also happens if the Unix socket file for Docker doesn’t have the correct ownership assigned.

1. Check ownership for the Docker Unix socket:

sudo ls -la /var/run/docker.sock

enter image description here

2. If necessary, grant the user ownership with:

sudo chown [username]:docker /var/run/docker.sock

Credits to Phonenixnap For answer

0

If have a Jenkins setup of Kubernetes cluster and I was facing the same issue while trying to build Dockerfiles using the Jenkins agent(pod gets launched in K8s cluster).

Steps to fix:

  1. Install Jenkins using the cmd:
helm repo add jenkinsci https://charts.jenkins.io/
helm upgrade --install my-jenkins jenkinsci/jenkins --set rbac.create=true --set agent.privileged=true --set serviceAccount.create=false  --set agent.runAsUser=0
  1. Install and configure docker plugin.

  2. create a Jenkins job and use the pipeline script mentioned below to install docker in the agent for building Dockerfile.

    pipeline {

    agent any
    
    stages {
        stage('Installing Dependencies'){
            steps {
                sh "apt-get update"
                sh "apt-get install build-essential python3 -y"
                sh "apt-get install unzip"
                sh "apt-get install ca-certificates"
                sh "apt-get install gnupg -y"
                sh "apt-get install lsb-release -y"
                sh "apt install curl"
                sh "curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg"
                sh 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null'
                sh "apt update"
                sh "apt -y install docker-ce docker-ce-cli containerd.io "
                sh 'usermod -aG docker "$(whoami)"'
                sh "service docker start"
                sh "sleep 10"
                sh "docker ps"
                sh "docker images"
            }
        }
    }
    

    }

enter image description here

enter image description here

0

Try this for latest solution,

sudo ln -s ~/Library/Containers/com.docker.docker/Data/docker.raw.sock /var/run/docker.sock DOCKER_HOST=unix:///var/run/docker.sock docker ps # test that it works using linked socket file

Melih Sevim
  • 930
  • 6
  • 9
-1

This issue can be resolved permanently by running 1. systemctl enable docker 2. service docker start

-1

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.

Christoph Kluge
  • 1,947
  • 8
  • 23
Pavankumar AN
  • 55
  • 1
  • 12
-1

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

-1

I just got the same error the docker commands did not work after installing docker desktop for macos even though it shows running, so the fix for it is i restarted my laptop and docker commands started working now and the pull commands and ps commands doesnot give error now.

FIX IS: Restart your laptop...

enter image description here

vijay
  • 609
  • 5
  • 9
-2

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

Hamdhan Azeez T
  • 429
  • 4
  • 9
  • I found I was actually in a shell inside the docker image! Just open another terminal and type `docker ps` to see what images are running. – RufusVS Jan 05 '22 at 19:49
  • This was useful for me I had updated Docker and some terms and conditions was changed At loggin, Docker was relaunched and request me permissions with my password and accept the new terms and conditions – Manuel Alanis Feb 15 '22 at 20:51