简体   繁体   English

使用sudo运行时无法连接到Docker守护程序

[英]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

You have to set environment variables with: 您必须使用以下方法设置环境变量:

eval "$(docker-machine env default)"

More about it here . 更多关于它的信息

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.

相关问题 Mac OS X sudo docker 无法连接到 Docker 守护程序。 docker 守护进程是否在此主机上运行? - Mac OS X sudo docker Cannot connect to the Docker daemon. Is the docker daemon running on this host? macOS - docker:无法连接到 unix:///var/run/docker.sock 的 Docker 守护程序。 docker 守护程序是否正在运行? - macOS - docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 无法连接到 macOS 上的 Docker 守护程序 - Cannot connect to the Docker daemon on macOS NodeJS / Express无法连接到docker中运行的mongodb - NodeJS / Express cannot connect to mongodb running in docker Docker 无法连接到 docker daemon macOS - Docker can't connect to docker daemon macOS 在 Macbook 中运行 Jenkins 管道时尝试连接到 Docker Daemon 时权限被拒绝 - Permission Denied while trying to connect to Docker Daemon while running Jenkins pipeline in Macbook minikube docker:来自守护程序的错误响应:在 MAC 中运行示例 docker 容器时连接被拒绝 - minikube docker: Error response from daemon: connection refused when running sample docker container in MAC 确保docker守护程序在脚本文件中的主机上运行 - Ensure docker daemon is running on the host in script file 无法从主机连接到在 Docker 中运行的 MySQL - Cannot connect to MySQL running in Docker from host machine 运行Django时无法连接到localhost - Cannot connect to localhost when running Django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM