I have setup a spring-boot docker container in an EC2 instance(EC2_IP) and I have a MySQL hosted in a different VM. I verified that that the mysql host(MYSQL_IP) is accessible from the EC2 instance hosting the docker container.
I am passing the spring.datasource.url parameters using the docker environment variables during docker run.
The spring boot app fails complaining with an error message access denied to user db_user@EC2_IP. This is the part I am unable to understand and fix. I don't understand why its trying to connect to the EC2_IP instead of db_user@MYSQL_IP.
I did a docker inspect and I verified that the environment variable for spring.datasoure.url is passed correctly and it is db_user@MYSQL_IP:3306.
I have spent hours trying to fix this problem, but no luck. Any help is appreciated.
To Clarify based on the comments, I have the datasource configured correctly.
Inside docker inspect, value of Args:
-Dspring.datasource.url=jdbc:mysql://MYSQL_IP:3306/test
Also, I checked if I pass some invalid IP (eg) some random text, then it throws an error saying host is invalid (This confirms, it is taking the host I pass in). However, if I configure to an external IP, it seems to resolve to the Host IP address (EC2_IP).