简体   繁体   中英

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?

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. Custom IP we provided - (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. HOST IP : 10.0.0.1, HOST PORT :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? 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.

Consider a scenario where you are using the host network for the container as well, probably by using the --network host . This way your container IP will be the same as the host IP. The container will be using the 5432 port of the host to run the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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