I want to migrate my application deployment to use docker / docker hub. Current production is configured to load traffic balance on two Linux servers running Apache, Tomcat, and MySQL. The Java web application connects to the master + slave MySQL DB via JDBC.
To minimize the impact of these changes, as a first step, I consider tomcat and web application containerization. Exiting Apache and MySQL running on the host (s) as it is now.
The problem I am facing is connecting an application running in a docker container with a MySQL database running on the host.
The best I can do at the moment is to connect to the docker container, get its IP address, and then use SQL GRANT so that this IP address can access the database. The problem is that every time you start a container, you potentially get a new IP address and therefore you must run a grant every time.
I played with this material for a while, and I cannot believe that there is no better solution than what I suggested above.
Has anyone done something like this? Everyone has any suggestions on how best to approach this issue.
Edit It has been suggested that “ Inside the Docker container, how can I connect to the local host of the machine? Is a duplicate of this, but the main problem still exists. Each time I create a Docker container from the image, I potentially get a new IP address for the container that should be granted access to the database, I wanted to try to avoid this.
Many thanks
source share