无法连接到Docker中的Docker

我遵循https://docs.docker.com/samples/docker/提供的说明,即

docker run --privileged --name some-docker -d docker:dind 

但是,我无法连接到泊坞窗服务。

 docker run -i -t --rm --link some-docker:docker docker:latest version Client: Version: 17.06.0-ce API version: 1.30 Go version: go1.8.3 Git commit: 02c1d87 Built: Fri Jun 23 21:15:15 2017 OS/Arch: linux/amd64 Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running? 

我可以通过telnet打开terminal

 docker run -i -t --rm --link some-docker:docker docker:latest /bin/sh / # telnet docker 2375 l HTTP/1.1 400 Bad Request Content-Type: text/plain; charset=utf-8 Connection: close 400 Bad RequestConnection closed by foreign host 

在同一个容器中运行docker -H docker info导致:

 docker -H docker info Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running? 

但是,如果我使用下面的Dockerfile来构build一个Dockerfile安装的基于Ubuntu的Dockerfile

 FROM ubuntu:latest RUN apt-get update && apt-get -y install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - RUN add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" RUN apt-get update && apt-get -y install docker-ce 

我可以连接到dockerdocker:

 docker build -t docker-ubuntu . docker run -i -t --rm --link some-docker:docker docker-ubuntu:latest /bin/sh # docker -H docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 17.06.0-ce Storage Driver: vfs Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4 init version: 949e6fa Security Options: seccomp Profile: default Kernel Version: 4.9.27-moby Operating System: Alpine Linux v3.6 (containerized) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 1.952GiB Name: b39967739fb9 ID: NDIF:PU7X:NA4B:IMI4:UH7V:VL4G:Q6L5:DPKP:NKDH:2XH6:XYDB:F2AV Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false No Proxy: *.local, 169.254/16 Registry: https://index.docker.io/v1/ Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled 

我在Mac OS X的docker-ce以及Ubuntu的Docker-ce上都尝试过。 同样的结果。 有任何想法吗?

– 特权并不意味着你有权访问docker-socket,而是所有设备/ dev和更多。

也就是说,一定要将docker-socket容量安装到你的容器中

docker run -v /var/run/docker.sock:/var/run/docker.sock

或者用docker-compose.yml模拟