I have a server which contains a python file that connects to two external MySQL DB’s. One of those DB’s can be easily reached while the other server requires that IP’s be whitelisted in order to have access to that DB. That server’s IP is already whitelisted and works as intended when ran.
The problem arises however when I attempt to run the docker-ized variation of the application. The first DB runs just as it does before but the second DB no longer works. When inside the container, I can ping the second DB and it works, but whenever I try to access it via the code hosted on the server, it doesn’t return data within any of the functions that utilize it. I noticed that the container has a separate IP, and may be causing issues since that docker container’s IP would not have been whitelisted and may be where the problem begins. I am fairly new to Docker, so any documentation links that would assist me would be extremely helpful.
Advertisement
Answer
So for anyone who is dealing with this situation in the future, I added the line
network_mode: “host”
to my docker.compose.yaml file. Here is some docs related to this: https://docs.docker.com/network/host/
Essentially what was happening is that the container could not be recognized by the whitelist and was not being allowed access to the second DB. With this change, it allowed the container to share the same network as the server it was being hosted on, and since that server has been whitelisted prior, it all worked out of the gate.
If you are using docker, then use
–net=host
within your run command. Here is a SO link about what this addition does: What does –net=host option in Docker command really do?