简体   繁体   English

Docker:如何从容器中访问服务器的公共IP?

[英]Docker: How do I access my server's public IP from within a container?

I'm running different apps as docker containers on a linux server. 我在Linux服务器上将不同的应用程序作为docker容器运行。 I'm able to access the docker containers just fine using SSL. 我可以使用SSL很好地访问docker容器。 The reverse proxy I'm using is traefik configured to proxy subdirectories instead of subdomains. 我正在使用的反向代理是traefik配置为代理子目录而不是子域。

These are my containers: 这些是我的容器:

Application A - accessible via https://abc.xyz/a 应用程序A-可通过https://abc.xyz/a访问

Application B - accessible via https://abc.xyz/b 应用程序B-可通过https://abc.xyz/b访问

Both applications are up and running and working correctly when accessing them from my browser. 从我的浏览器访问它们时,这两个应用程序都已启动并正在运行并且可以正常工作。

Now I need to embed Application B in Application A . 现在,我需要将应用程序B嵌入到应用 程序A中 I know I could just use the container's internal IP (since they are on the same network), however, the embedded application must be accessible to Application A as well as to my local browser - so I need to use a publicly facing IP/URL. 我知道我只能使用容器的内部IP(因为它们位于同一网络上),但是, 应用A和本地浏览器都必须可以访问嵌入式应用-因此,我需要使用面向公众的IP / URL 。

The problem now is that I simply cannot access https://abc.xyz/b from Application A . 现在的问题是我根本无法从应用程序A访问https://abc.xyz/b All the below commands are executed inside the Application A docker container. 以下所有命令均在Application A docker容器内执行。

Ping is working: Ping正在工作:

$ ping abc.xyz
64 bytes from 150.150.150.150: seq=0 ttl=64 time=0.204 ms

So DNS is working. 因此DNS正在工作。

However wget shows: 但是wget显示:

$ wget https://abc.xyz/b
Connecting to abc.xyz (150.150.150.150)
(Nothing happens)

I simply cannot figure out where the problem is. 我根本无法弄清楚问题出在哪里。 Is it in traefik or is this a docker limitation? 是在traefik还是这是traefik限制?

After some more research I found out that it wasn't related to docker or traefik at all. 一些调查研究后,我发现,它并没有相关的dockertraefik的。 The host linux had a firewall enabled ( ufw ) that was blocking the requests from the docker containers, since it wasn't configured properly. 主机linux启用了防火墙( ufw ),由于未正确配置,该防火墙阻止了来自docker容器的请求。

I now allowed access from the containers and it works. 我现在允许从容器访问它并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM