Actually m facing the issue of docker networking between cluster in which nodes are deployed over different host and for solving the issue I have use: docker run -idt --net=host mongodb /bin/bash So after run this command I have found container's application is exposing its port and is running on hosts IP, this solved my problem and all the nodes are able to communicate with others but I want to know is running container like this is a right way.....? Shall we use this way in production ?
1 Answer
No you should not be using --net=host in production. That said it really is dependent on your specific environment, maybe you have other security measures in place that make is ok to run your container fully open to the host. By using --net=host you are essentially just making a 1 to 1 mapping of all the container's ports to host's ports. So your mongodb port is exposed to anything that can access your host.
You should be using a docker overlay network to network containers together that are running on different hosts.
https://docs.docker.com/engine/userguide/networking/dockernetworks/