Docker MySQL: Communication link failure

I have created a docker container of mysql with the database init. Now i am trying to connect my local spring boot project with that mysql in container. It always give me communication link failure.

spring.datasource.url = jdbc:mysql://localhost:3306/erp
spring.datasource.username = sa
spring.datasource.password = password

I also tried changing localhost with the name of container but still nothing works.

Source: StackOverflow