Cannot connect to docker daemon

2019-03-03 13:34发布

问题:

I have tried everything: add user, tried it with sudo but i didnt fix it.

I tried it as a : sudo docker ps and docker ps

Docker version : 1.11.2 OS/Archlinux

gives an error : Cannot connect to the Docker daemon. Is the docker daemon running on this host?

systemctl status docker :
 ● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service;  enabled;   vendor preset: disabled)
Active: active (running) since Tue 2016-08-16 12:34:14 UTC; 13min ago
 Docs: https://docs.docker.com
Main PID: 2323 (docker)
Tasks: 21 (limit: 4915)
Memory: 24.2M
  CPU: 649ms
CGroup: /system.slice/docker.service
       ├─2323 /usr/bin/docker daemon -H fd://
       └─2339 docker-containerd -l /var/run/docker/libcontainerd /docker-containerd.sock --runtime docker-run
Aug 16 12:34:13 localhost docker[2323]: time="2016-08-16T12:34:13.730808484Z" level=info msg="[graphdriver] usin
Aug 16 12:34:13 localhost docker[2323]: time="2016-08-16T12:34:13.762838102Z" level=info msg="Graph migration to
Aug 16 12:34:13 localhost docker[2323]: time="2016-08-16T12:34:13.769883452Z" level=info msg="Firewalld running:
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.023823826Z" level=info msg="Default bridge (do
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.179897054Z" level=info msg="Loading containers
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.179994020Z" level=info msg="Loading containers
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.180008132Z" level=info msg="Daemon has complet
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.180026066Z" level=info msg="Docker daemon" com
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.187118716Z" level=info msg="API listen on 0.0.
Aug 16 12:34:14 localhost systemd[1]: Started Docker Application Container Engine.


ps aux | grep docker
root      2681  0.1  0.9 553580 35416 ?        Ssl  12:59   0:00 /usr/bin/docker daemon -H fd://
root      2694  0.0  0.3 287016 11724 ?        Ssl  12:59   0:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc --start-timeout 2m
cuneyt    2835  0.0  0.0  11056  2228 pts/1    S+   13:01   0:00 grep docker

EDIT : When i run manualy docker daemon is working and API listen on /var/run/docker.sock

When i start it with systemctl start docker API Listen on 0.0.0.0:3000 i think that is the problem but i dont know how to fix it any idea ?

systemctl cat docker.service

[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/docker daemon -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

[Install]
WantedBy=multi-user.target

回答1:

The installation documentation states:

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.

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

To create the docker group and add your user:

Login as a user with sudo privileges. (the one you used to install docker) Create the docker group.

$ sudo groupadd docker

Add your user to docker group.

$ sudo usermod -aG docker $USER

Log out and log back in. This ensures your user is running with the correct permissions. Verify your work by running docker without sudo.

$ docker run hello-world

If you're still getting the same error, check if the DOCKER_HOST environment variable is not set for your shell. If it is, unset it.

$ unset DOCKER_HOST

Hope this helps



标签: docker