首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法通过Google Cloud VM的外部IP访问nginx容器

问无法通过Google Cloud VM的外部IP访问nginx容器
EN

Stack Overflow用户
提问于 2020-09-24 07:30:27
回答 2查看 830关注 0票数 2

我有一个google cloud虚拟机,在端口8080上运行nginx docker容器。当我使用curl http://localhost:8080时,可以从机器内部访问nginx页面。然而,当我打开机器的外部IP (使用端口8080)时,我得到了chrome中的ERR_CONNECTION_REFUSED。我在创建虚拟机时启用了http/https防火墙选项。

下面是我使用的docker run命令和localhost上的curl检查:

代码语言:javascript
复制
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 )

代码语言:javascript
复制
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转发“关闭有关吗?(见上图)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-24 16:18:54

我使用以下命令运行我的容器

代码语言:javascript
复制
sudo docker run -d -p [Internal IP]:8080:80 nginx

我可以在http://[External上访问nginx页面]:8080

此外,还需要添加问题中提到的防火墙规则。

票数 0
EN

Stack Overflow用户

发布于 2020-09-24 10:32:36

根据Docker docs,docker run语句中的-p 8080:80参数告诉它将主机上的端口8080发布到容器上的端口80,因此在本例中,您将通过访问端口8080上的节点的外部IP来从外部访问它。34.68.171.6:8080

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64037604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档