Search code examples
dockeriptables

Docker container cant connect outside docker0


I have a server with docker that hosts 2 docker containers. These containers are running a Spring boot 2 application. In 1 container I want to connect to the other container and I am having timeout issues. The reason has to do with iptables. When I set the input policy to ACCEPT then everything works however when I set the INPUT policy to drop I get a timeout exception.

Container 1 is trying to connect to container 2 through the outside domain name. So Container 1 tries and connects to subdomain.domain.com. I beleive this means that docker eventually connects through eth0 instead of through docker internally. Is this the reason that the container cant connect to the other container and I must set the INPUT policy to ACCEPT?

How can I setup iptables so that a docker container may connect to another docker container if using the "outside" domain name?


Solution

  • You can also make the two containers as part of service stack and either link the containers or even possibly create a separate network and then link the containers thereby isolating the two containers.

    This link provides a simple example