我有一个google cloud虚拟机,在端口8080上运行nginx docker容器。当我使用curl http://localhost:8080时,可以从机器内部访问nginx页面。然而,当我打开机器的外部IP (使用端口8080)时,我得到了chrome中的ERR_CONNECTION_REFUSED。我在创建虚拟机时启用了http/https防火墙选项。
下面是我使用的docker run命令和localhost上的curl检查:
aayush_pathak15@instance-1:~/devops-environment$ sudo docker run -d -p 8080:80 nginx
f398231940eeb7194e0b4deb50936d7581cf32a451583e162cac40e829f9ebff
aayush_pathak15@instance-1:~/devops-environment$ curl http://localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
aayush_pathak15@instance-1:~/devops-environment$ 这是我的虚拟机上所有端口的列表(以及监听端口8080的docker )
aayush_pathak15@instance-1:~/devops-environment$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 583/sshd
tcp6 0 0 :::8080 :::* LISTEN 8936/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 583/sshd
udp 0 0 0.0.0.0:68 0.0.0.0:* 310/dhclient
udp 0 0 127.0.0.1:323 0.0.0.0:* 402/chronyd
udp6 0 0 ::1:323 :::* 402/chronyd 我尝试添加另一个防火墙规则以允许所有端口(请忽略显示为“jenkins”的无关命名)

以下是我的计算机详细信息

这会与"IP转发“关闭有关吗?(见上图)
发布于 2020-09-24 16:18:54
我使用以下命令运行我的容器
sudo docker run -d -p [Internal IP]:8080:80 nginx我可以在http://[External上访问nginx页面]:8080
此外,还需要添加问题中提到的防火墙规则。
发布于 2020-09-24 10:32:36
根据Docker docs,docker run语句中的-p 8080:80参数告诉它将主机上的端口8080发布到容器上的端口80,因此在本例中,您将通过访问端口8080上的节点的外部IP来从外部访问它。34.68.171.6:8080
https://stackoverflow.com/questions/64037604
复制相似问题