您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

docker容器内部无法连接宿主机所在局域网

2025/11/20 17:46:00发布20次查看
使用centos镜像创建容器,在容器内部署php项目,由于要向宿主机所在局域网的另一台服务器请求接口服务,发起的http请求始终连接不上,但可以连接国际互联网。
2.
宿主机ip:172.20.20.152,
请求接口的目标服务器ip:172.17.3.97
创建docker容器的命令:
docker run -p 80:80 --name=mycns -it eeb3a076a0be /bin/bash
进入容器后,执行命令:
ping 172.17.3.97
返回结果是:
from 172.17.0.3 icmp_seq=1 destination host unreachable
from 172.17.0.3 icmp_seq=2 destination host unreachable
from 172.17.0.3 icmp_seq=3 destination host unreachable
from 172.17.0.3 icmp_seq=4 destination host unreachable
from 172.17.0.3 icmp_seq=5 destination host unreachable
from 172.17.0.3 icmp_seq=6 destination host unreachable
from 172.17.0.3 icmp_seq=8 destination host unreachable
from 172.17.0.3 icmp_seq=9 destination host unreachable
安装docker版本信息:
docker version
返回:
client version: 1.7.1
client api version: 1.19
go version (client): go1.4.2
git commit (client): 786b29d/1.7.1
os/arch (client): linux/amd64
server version: 1.7.1
server api version: 1.19
go version (server): go1.4.2
git commit (server): 786b29d/1.7.1
os/arch (server): linux/amd64
3.
宿主机执行ifconfig命令,返回:
docker0 link encap:ethernet hwaddr ee:25:c5:da:10:47
inet addr:172.17.42.1 bcast:0.0.0.0 mask:255.255.0.0 inet6 addr: fe80::200:ff:fe00:0/64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:64400 errors:0 dropped:0 overruns:0 frame:0 tx packets:69800 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:3945235 (3.7 mib) tx bytes:105962604 (101.0 mib)

eth0 link encap:ethernet hwaddr f2:3d:f0:2b:43:31
inet addr:172.20.20.152 bcast:172.20.255.255 mask:255.255.0.0 inet6 addr: fe80::f03d:f0ff:fe2b:4331/64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:29702118 errors:0 dropped:0 overruns:0 frame:0 tx packets:583992 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 rx bytes:2997801386 (2.7 gib) tx bytes:73288231 (69.8 mib)

lo link encap:local loopback
inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr: ::1/128 scope:host up loopback running mtu:65536 metric:1 rx packets:7059 errors:0 dropped:0 overruns:0 frame:0 tx packets:7059 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:4819120 (4.5 mib) tx bytes:4819120 (4.5 mib)

veth50f5616 link encap:ethernet hwaddr ee:25:c5:da:10:47
inet6 addr: fe80::ec25:c5ff:feda:1047/64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:17 errors:0 dropped:0 overruns:0 frame:0 tx packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:1014 (1014.0 b) tx bytes:468 (468.0 b)

4.
宿主机本可以正常连接172.17.3.97这台机器,但docker服务启动后,无法正常连接。
来一位大神帮看看呵呵
回复内容: 使用centos镜像创建容器,在容器内部署php项目,由于要向宿主机所在局域网的另一台服务器请求接口服务,发起的http请求始终连接不上,但可以连接国际互联网。
2.
宿主机ip:172.20.20.152,
请求接口的目标服务器ip:172.17.3.97
创建docker容器的命令:
docker run -p 80:80 --name=mycns -it eeb3a076a0be /bin/bash
进入容器后,执行命令:
ping 172.17.3.97
返回结果是:
from 172.17.0.3 icmp_seq=1 destination host unreachable
from 172.17.0.3 icmp_seq=2 destination host unreachable
from 172.17.0.3 icmp_seq=3 destination host unreachable
from 172.17.0.3 icmp_seq=4 destination host unreachable
from 172.17.0.3 icmp_seq=5 destination host unreachable
from 172.17.0.3 icmp_seq=6 destination host unreachable
from 172.17.0.3 icmp_seq=8 destination host unreachable
from 172.17.0.3 icmp_seq=9 destination host unreachable
安装docker版本信息:
docker version
返回:
client version: 1.7.1
client api version: 1.19
go version (client): go1.4.2
git commit (client): 786b29d/1.7.1
os/arch (client): linux/amd64
server version: 1.7.1
server api version: 1.19
go version (server): go1.4.2
git commit (server): 786b29d/1.7.1
os/arch (server): linux/amd64
3.
宿主机执行ifconfig命令,返回:
docker0 link encap:ethernet hwaddr ee:25:c5:da:10:47
inet addr:172.17.42.1 bcast:0.0.0.0 mask:255.255.0.0 inet6 addr: fe80::200:ff:fe00:0/64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:64400 errors:0 dropped:0 overruns:0 frame:0 tx packets:69800 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:3945235 (3.7 mib) tx bytes:105962604 (101.0 mib)

eth0 link encap:ethernet hwaddr f2:3d:f0:2b:43:31
inet addr:172.20.20.152 bcast:172.20.255.255 mask:255.255.0.0 inet6 addr: fe80::f03d:f0ff:fe2b:4331/64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:29702118 errors:0 dropped:0 overruns:0 frame:0 tx packets:583992 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 rx bytes:2997801386 (2.7 gib) tx bytes:73288231 (69.8 mib)

lo link encap:local loopback
inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr: ::1/128 scope:host up loopback running mtu:65536 metric:1 rx packets:7059 errors:0 dropped:0 overruns:0 frame:0 tx packets:7059 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:4819120 (4.5 mib) tx bytes:4819120 (4.5 mib)

veth50f5616 link encap:ethernet hwaddr ee:25:c5:da:10:47
inet6 addr: fe80::ec25:c5ff:feda:1047/64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:17 errors:0 dropped:0 overruns:0 frame:0 tx packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:1014 (1014.0 b) tx bytes:468 (468.0 b)

4.
宿主机本可以正常连接172.17.3.97这台机器,但docker服务启动后,无法正常连接。
来一位大神帮看看呵呵
找到原因了: http://dev.bidlust.com/?p=103
你可以不适用桥接网络,使用仅主机网络,这样就和主机一模一样了,docker run添加参数:--net host
应该是防火墙给拦了
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product