[英]Cannot connect to the Docker daemon when running with sudo
My Docker service is up and running. 我的Docker服务已启动并正在运行。 However when attempting to use Docker by running it with
sudo
, eg: 但是当试图通过运行
sudo
来使用Docker时,例如:
12:40:26/~ $ sudo docker pull fluxcapacitor/pipeline
Using default tag: latest
I have got the following error: 我有以下错误:
Warning: failed to get default registry endpoint from daemon (Cannot connect to
the Docker daemon. Is the docker daemon running on this host?). Using system
default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Note that I had already followed the answers on Mac OS X sudo docker Cannot connect to the Docker daemon. 请注意,我已经按照Mac OS X上的答案sudo docker无法连接到Docker守护程序。 Is the docker daemon running on this host?
docker守护程序是否在此主机上运行?
as follows: 如下:
docker-machine start default docker-machine启动默认值
12:40:36/~ $ docker-machine start default
Starting "default"...
Machine "default" is already running.
docker ps 码头工人
12:41:20/~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
So what more needs to be done? 那么还有什么需要做的呢?
This is: 这是:
$ docker --version
Docker version 1.11.2, build b9f10c9
on El Capitan
. 在
El Capitan
。
Output of docker-machine env default
docker-machine env default
输出
$ eval "$(docker-machine env default)"
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/macuser/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
The following command exports a few environment variables that the subsequent docker commands use: 以下命令导出后续docker命令使用的一些环境变量:
eval "$(docker-machine env default)"
However, if you launch docker with sudo, the exported environment variables are not accessible by the docker executable. 但是,如果使用sudo启动docker,则docker可执行文件无法访问导出的环境变量。 You could potentially get it to work by passing
-E
flag to sudo
, eg: 您可以通过将
-E
标志传递给sudo
来使其工作,例如:
sudo -E docker pull fluxcapacitor/pipeline
But much easier option is to use docker without root like: 但更容易的选择是使用没有root的docker,如:
docker pull fluxcapacitor/pipeline
I had same probelem on my MAC, when attempted 尝试时,我的MAC上有相同的探测器
# eval "$(docker-machine env default)"
got this error 得到了这个错误
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": x509: certificate is valid for 192.168.99.101, not 192.168.99.100
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
to regenerate certificates, find out the docker-machines available; 重新生成证书,找出可用的码头机器;
# docker-machine ls
Output of avalable docker machines (omitted others) 可出售的码头机器的输出(省略其他)
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 Unknown Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate is valid for 192.168.99.101, not 192.168.99.100
Generate certificates for this default docker-machine 为此默认docker-machine生成证书
# docker-machine regenerate-certs default
and then setup docker-machine env to default
docker-machine; 然后将docker-machine env设置为
default
docker-machine;
# eval "$(docker-machine env default)"
and it works normally after that. 并且在那之后它正常工作。
I have also tried the same but did not work. 我也尝试了同样但没有奏效。
later I have tried these steps on AWS CLI 后来我在AWS CLI上尝试了这些步骤
$ sudo nano /etc/docker/daemon.json
{
"dns": ["8.8.8.8", "8.8.4.4"]
}
$ sudo service docker restart
$ docker pull hello-world
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.