Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Networking docker仅在主机上公开端口_Networking_Docker_Port - Fatal编程技术网

Networking docker仅在主机上公开端口

Networking docker仅在主机上公开端口,networking,docker,port,Networking,Docker,Port,对不起,我问了个愚蠢的问题。我正在使用docker,并尝试向localhost公开端口。 我正在使用以下命令行: docker run -d -p 127.0.0.1:8080:8081 --name nexus sonatype/nexus 我正在执行以下命令: wget nexus:8080 --2015-03-26 19:31:58-- http://nexus:8080/ Résolution de nexus (nexus)... 127.0.53.53 Connexion ver

对不起,我问了个愚蠢的问题。我正在使用docker,并尝试向localhost公开端口。 我正在使用以下命令行:

docker run -d -p 127.0.0.1:8080:8081 --name nexus sonatype/nexus
我正在执行以下命令:

wget nexus:8080
--2015-03-26 19:31:58--  http://nexus:8080/
Résolution de nexus (nexus)... 127.0.53.53
Connexion vers nexus (nexus)|127.0.53.53|:8080...échec: Connexion refusée.
我对ping命令有问题,但是为什么我找不到nexus服务器

我有支票,所有端口都在(iptables)上打开


谢谢

您从哪里运行wget?您只绑定到主机上的localhost接口,因此只能从主机本身访问容器。如果在
docker run
命令中使用
0.0.0.0:8080:8081
,是否有效?iirc0.0.0.0是默认值,因此也应该使用
8080:8081

如果您不想让本地网络之外的任何人都可以访问该端口,请使用您的本地IP地址,您可以通过运行
ifconfig
找到该地址。例如,我在本地网络上的IP是192.168.1.103,因此我会:

docker run -d -p 192.168.1.103:8080:8081 --name nexus sonatype/nexus

这样访问docker是个问题。 您可以尝试以下方法来测试服务器:

docker exec -it nexus wget http://nexus:8080/
这将在docker映像中生成本地wget

该docker可以从节点外部访问,也可以从节点内部访问。 只是没有从通用网络接口到docker接口的路由