I try to run a Springboot app with mysql connection on Docker. Without docker, it works well. But when I try to deploy on a container, I have com.mysql.cj.exceptions.CJCom
there is a difference between networks
and links
. use links like the one below
version: '2'
services:
web:
build: .
links:
- "db:database"
db:
image: postgres
this switch will add ID and IP address of one docker container in another on. in this way they can connect to each other. for more info check following link.
As your Spring Boot application is also launched in a docker image, you can't used the port exposed by docker, but instead you need to use the original port of the image.
In application.properties
you need to use:
spring.datasource.url = jdbc:mysql://mysql:3306/db