Docker tcp只能用"localhost"不能用“127.0.0.1”或ip连接
Docker tcp can only use "localhost" but not "127.0.0.1" or ip to connect
我已经在 ubuntu18.04 上安装了最新的 docker 版本并且我已经配置了这个文件:
$ cat /etc/systemd/system/docker.service.d/hosts.conf
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
然后:
sudo systemctl daemon-reload
sudo systemctl restart docker.service
现在我可以看到 docker 从远程 tcp 开始:
ps -ef|grep docker
root 16142 1 0 14:08 ? 00:00:00 /usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
现在我可以:
docker -H tcp://localhost:2375 version
有效并打印:
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:29:52 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
但是我无法使用“127.0.0.1”或ip访问:
docker -H tcp://l27.0.0.1:2375 version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:29:52 2019
OS/Arch: linux/amd64
Experimental: false
error during connect: Get http://l27.0.0.1:2375/v1.40/version: dial tcp: lookup l27.0.0.1: no such host
此外,使用 ip 失败:
$ ifconfig|grep inet
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:8fff:feac:e6fd prefixlen 64 scopeid 0x20<link>
inet 10.190.151.77 netmask 255.255.252.0 broadcast 10.190.151.255
inet6 fe80::215:5dff:febd:e523 prefixlen 64 scopeid 0x20<link>
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
这也会失败:
docker -H tcp://10.190.151.77:2375 version
我已经通过 "sudo ufw disable" 禁用了防火墙。不确定我是否应该配置 docker 或 ubuntu 网络?只是想知道为什么会这样以及如何让它发挥作用?
我发现了你的问题!
你用 "lower case L" 而不是 127.0.0.1 ^^'
写了 l27.0.0.1
我已经在 ubuntu18.04 上安装了最新的 docker 版本并且我已经配置了这个文件:
$ cat /etc/systemd/system/docker.service.d/hosts.conf
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
然后:
sudo systemctl daemon-reload
sudo systemctl restart docker.service
现在我可以看到 docker 从远程 tcp 开始:
ps -ef|grep docker
root 16142 1 0 14:08 ? 00:00:00 /usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
现在我可以:
docker -H tcp://localhost:2375 version
有效并打印:
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:29:52 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
但是我无法使用“127.0.0.1”或ip访问:
docker -H tcp://l27.0.0.1:2375 version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:29:52 2019
OS/Arch: linux/amd64
Experimental: false
error during connect: Get http://l27.0.0.1:2375/v1.40/version: dial tcp: lookup l27.0.0.1: no such host
此外,使用 ip 失败:
$ ifconfig|grep inet
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:8fff:feac:e6fd prefixlen 64 scopeid 0x20<link>
inet 10.190.151.77 netmask 255.255.252.0 broadcast 10.190.151.255
inet6 fe80::215:5dff:febd:e523 prefixlen 64 scopeid 0x20<link>
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
这也会失败:
docker -H tcp://10.190.151.77:2375 version
我已经通过 "sudo ufw disable" 禁用了防火墙。不确定我是否应该配置 docker 或 ubuntu 网络?只是想知道为什么会这样以及如何让它发挥作用?
我发现了你的问题!
你用 "lower case L" 而不是 127.0.0.1 ^^'
写了 l27.0.0.1