简体   繁体   English

如果docker容器ip和外部网络ip相同,那么如果执行telnet,则哪个响应? 任何想法

[英]If docker container ip and external network ip is same, then which one will get respond if will do telnet? any idea

If docker container IP and external network IP is the same, then which one will get respond if it will do telnet? 如果docker容器IP和外部网络IP是相同的,那么如果它执行telnet,将响应哪一个?

I know below configuration is the worst configuration, but I want to know the behaviour. 我知道以下配置是最差的配置,但我想知道其行为。

Give you one example 给你一个例子

My application is running in localhost which is talking to the database inside the docker container. 我的应用程序在localhost中运行,该主机正在与docker容器内的数据库进行通信。 Custom IP we provided - (IP : 10.0.0.1, PORT :5432) 我们提供的自定义IP-(IP:10.0.0.1,PORT:5432)

Another database running outside the container, let say both container (IP and port) and host (IP and port) are the same. 另一个在容器外部运行的数据库,可以说容器(IP和端口)和主机(IP和端口)是相同的。 HOST IP : 10.0.0.1, HOST PORT :5432 主机IP:10.0.0.1,主机端口:5432

Which one will connect by application host/container-database or both the database? 哪一个将通过应用程序主机/容器数据库或两者连接?

or 要么

If will do the telnet 10.0.0.1 5432? telnet 10.0.0.1 5432是否可以? which one will respond and why? 哪一个会回应,为什么?

Explain in Diagram 图解说明

I don't think that's possible, even if you have the same IP (somehow) for the container and the host, you won't be able to map the container port 5432 to the host port 5432, because there's already an application (host dB) running on that port. 我认为这是不可能的,即使容器和主机具有相同的IP(以某种方式),您也无法将容器端口5432映射到主机端口5432,因为已经有一个应用程序(主机dB)在该端口上运行。

Consider a scenario where you are using the host network for the container as well, probably by using the --network host . 考虑一个场景,其中您也将容器的主机网络也可以使用--network host This way your container IP will be the same as the host IP. 这样,您的容器IP将与主机IP相同。 The container will be using the 5432 port of the host to run the dB. 容器将使用主机的5432端口运行dB。 Now, if you try to start the dB on the host using the same port, you should get an error that port is already being used. 现在,如果您尝试使用同一端口在主机上启动dB,您将得到一个错误,表明该端口已被使用。

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

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