45

I have installed docker on ubuntu 14.04, it told me installed successfully. Then I entered sudo docker version, it returned

Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.2
 Git commit:   a34a1d5
 Built:        Fri Nov 20 13:12:04 UTC 2015
 OS/Arch:      linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

I entered sudo service docker status, I got

docker start/running, process 8063

I tried sudo docker images and sudo docker info, I got the same reply:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

I do not know why it returned this, I tried to pull ubuntu using sudo docker pull ubuntu, and got

Using default tag: latest
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Please tell me how can I solve this problem, how can I pull and run docker image. And is docker -d the same as docker deamon?

thiiiiiking
  • 1,233
  • 3
  • 12
  • 16
  • Possible duplicate of [Docker can't connect to docker daemon](https://stackoverflow.com/questions/21871479/docker-cant-connect-to-docker-daemon) – kenorb Apr 08 '18 at 15:26

8 Answers8

50

You need to add your current user to docker group like following:

sudo usermod -aG docker <your username>

Also, you can use USER environment variable like:

sudo usermod -aG docker $USER

Then restart the system. As the docker documentation says:

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.

To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
  • 3
    I got the same output on ubuntu 14.04 LTS, but setting `sudo usermod -aG docker ` with my username didn't worked. After rebooting my system I get still `Cannot connect to the Docker daemon. Is the docker daemon running on this host?` the same. Any idea? – b00r00x0 Feb 07 '16 at 19:16
  • Same for me: ubuntu 14.04 LTS, sudo usermod ..etc... didn't work while sudo docker ps works... – chrx Jun 08 '16 at 09:07
  • @chrx Did you restart the system? Also you can test ps06756 solution – Ali Dehghani Jun 08 '16 at 09:12
  • yes i did try both to logout/login and to restart the machine, but nothing changed – chrx Jun 08 '16 at 09:56
8

If adding user to the docker group doesn't work then try restarting the service:

sudo service docker restart 
Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97
6

The only way that worked for me (on ubuntu xenial):

sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
newgrp docker

Found here

rideronthestorm
  • 727
  • 1
  • 13
  • 32
1

In my case working answer is

$ docker-machine create -d virtualbox default
$ eval "$(docker-machine env default)"
Nick
  • 9,735
  • 7
  • 59
  • 89
1

Am not sure if others have used this approach, but when I face this issue of "Is the docker daemon running on this host?", Unsetting docker related environment variables helps recognize the docker daemon running on my machine. The same error message shows up when I open a new tab in the terminal window and unsetting has helped resolve it.

unset ${!DOCKER_*} 
gammabowl
  • 31
  • 5
1

If all the other solutions above don't work you can try checking the ownership of /var/run/docker.sock:

ls -l /var/run/docker.sock

If you're not the owner then change ownership with the command:

sudo chown *your-username* /var/run/docker.sock

Then you can go ahead and try executing the Docker commands hassle-free :D

kevthanewversi
  • 3,686
  • 4
  • 27
  • 27
0

None of the answers here fixed my issue, so i'm posting my solution here in case it helps anyone. This command fixed the issue for me:

$ docker context use default

Laguilhoat
  • 325
  • 1
  • 6
-1

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

If it's showing this error please check your typecode:

->   docker build -t swagger-ui-builder .

is correctly given. If miss some value show error .

Refer to this site: http://swagger.io/swagger-ui/

Jeff
  • 12,555
  • 5
  • 33
  • 60
Dharma Raj
  • 11
  • 2