Docker Community Forums

Share and learn in the Docker community.

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

Add user in docker group
sudo usermod -aG docker $USER

and then will making relogin in system

9 Likes

Thank you. This was exactly my problem on ubuntu.

thanks, this solved my problem

thanks for saving my day!

:persevere:

Thanks you @programmerq

Thank you @programmerq

For Ubuntu 16.04

Inside file /lib/systemd/system/docker.service change:
ExecStart=/usr/bin/dockerd fd://
with
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375

Inside file /etc/init.d/docker change:
DOCKER_OPTS=
with
DOCKER_OPTS="-H tcp://0.0.0.0:2375"

and then restart your computer.

8 Likes

@decomads - Ur the man! Thanks

1 Like

Probably, you should set the DNS server in daemon.json, located in /etc/docker/daemon.json.

TOTALLY, you need 3 steps:
(1) check your dns server you’re using;
(2) then, set dns server in daemon.json;
(3) finnaly, restart docker service.

For more details about the steps you can look through my reply in the bottom fo this post https://forums.docker.com/t/communication-between-containers-and-wider-world/24295/8

Would like to share the my experience, I had also encounter the same error while jenkins trigger build jobs, in order to overcome this issue tried the below mentioned solutions & its work for me.

Error:
====>
[docker-jenkins-job] $ /bin/sh -xe /tmp/hudson2951930380198129000.sh
++ /usr/bin/docker ps -aq --filter ancestor=myapache_image
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

  • /usr/bin/docker stop
    docker: “stop” requires a minimum of 1 argument.
    See ‘/usr/bin/docker-current stop --help’.

Solution:
=======>
Docker & Jenkins Issue
==================>

sudo gpasswd -a jenkins docker

Edit the following file : vi /usr/lib/systemd/system/docker.service

And edit this rule to expose the API : ExecStart=/usr/bin/docker daemon -H unix:// -H tcp://localhost:2375

Now it’s time to reload and restart your Docker daemon:

systemctl daemon-reload
systemctl restart docker

Then I restarted jenkins and I was able to perform docker commands as jenkins user in my jenkins jobs

sudo service jenkins restart

Results:
======>
[docker-jenkins-job] $ /bin/sh -xe /tmp/hudson6409609007865461459.sh
++ /usr/bin/docker ps -aq --filter ancestor=myapache_image

  • /usr/bin/docker rm -f 86ed79e70f88
    86ed79e70f88
    [docker-jenkins-job] $ /bin/sh -xe /tmp/hudson3750921594572949914.sh
  • /usr/bin/docker build -t myapache_image .
    Sending build context to Docker daemon 60.93 kB

Step 1 : FROM ubuntu:latest
—> 104bec311bcd
Step 2 : MAINTAINER Amit Vashist amitvashist7@gmail.com

It work’s.

1 Like

Soooo for running docker in docker, on windows 10. Powershell is run as admin. I have a manager and a worker up

the compose yaml file is as such:

version: '2’
services:
manager:
image: docker:latest
ports:
- “2375”
- "8080"
privileged: true
tty: true
worker:
image: docker:latest
ports:
- "8080"
privileged: true
tty: true

i dont know why or what tty: true even does but its the only way to get it to stay up for some reason.

i try to init the manager with:

docker-compose exec manager docker swarm init
–listen-addr 0.0.0.0:2377

also tried with the port being 0.0.0.0:2375 as what is open in the compose yaml.

when i run the command

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

here is the result of a docker-compose ps

   Name                   Command           State                        Ports

swarmtest_manager_1 docker-entrypoint.sh sh Up 0.0.0.0:32782->2375/tcp, 0.0.0.0:32781->8080/tcp
swarmtest_worker_1 docker-entrypoint.sh sh Up 0.0.0.0:32780->8080/tcp

Please help! Running and testing services in the docker in docker environment woudl be ideal, although i still dont like compose as i am trying to learn how to use it better, creating a docker-machine and using the docker swarm mode seems much easier. But i am still a docker noob.

I ran into this error message when I was trying to use a distribution of Docker installed via Homebrew on Mac OS. Reinstalling Docker from the official Docker site resolved this for me.

1 Like

Hi,
I am getting following error. Can anybody help me out ?

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

my docker daemon is getting failed to start, when ever I restart the laptop
I have ubuntu16.04 xenial distrubution and docker v17.03,
I have tried to reinstalled docker but still that didn’t work

 sudo service docker stop 

   sudo service docker start 

(this thing fixes till the system is on )

but again when i restart or switch on/off the system it fails to start …

Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket firewalld.service
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd://
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

this is the docker.service in lib/systemd/system

This was the fix for me!

This work’s, Thanks…

Once the above configuration has been configured, Jenkins work’s fine for docker build. But when i try to run docker commands manually in that Machine i am unable to get response for manually typed docker commands.

Is this normal ?

usermode -aG docker gitlab-runner

solved the problem! This work for me. Lots of thank you.

Hi Rodney,

Once the above configuration has been configured, Jenkins work’s fine for docker build. But when i try to run docker commands manually in that Machine i am unable to get response for manually typed docker commands.

Did you faced this issue after this configuration.