Find the IP address of the host machine in the docker network. If you are using docker-compose.yml version: "3" , this IP address is 172.18.0.1 : 172.18.0.1 , but confirm the search for the "Gateway" of your container (your host):
docker inspect <container-id-or-name> | grep Gateway "Gateway": "", "IPv6Gateway": "", "Gateway": "172.18.0.1", "IPv6Gateway": "",
So, inside your docker application, specify MySQL as follows: 172.18.0.1:3306 { 172.18.0.1:3306 (possibly in the configuration file). Note that this IP address is fixed as long as the docker network is still the same (the network is created using docker-compose, and it is not deleted if you do not run docker-compose down )
Also, check that your MySQL is listening on all its interfaces. In my.cnf search for bind-address , which should be 0.0.0.0 (consider security issues if your server has a public IP address).
Alternatively, you can bring the same network to the container as your host to split the local host so that the container finds mysql there. Use network mode as a "host":
version: '3' services: web-app: build: context: . dockerfile: web-app/Dockerfile ports: - 8080:8080 network_mode: "host"
Then specify the mysql value in hibernate.properties as follows: localhost:3306
source share