Spring service in docker container cannot connect to mysql in docker container Spring service in docker container cannot connect to mysql in docker container docker docker

Spring service in docker container cannot connect to mysql in docker container


change this url: jdbc:mysql://localhost:3306/MyDB to:

url: jdbc:mysql://db:3306/MyDB

localhost refer here to your app container , compose will handel that to you by using service names

you need also to make sure that the DB is up and running before the APP container is , you can use somehting like wait-for-it.sh see this