Hello. I am pretty new to docker. I have created a small springboot application that uses mysql for data storage. Both my application and mysql are on the same host machine, and in this case the application runs fine. Now I am trying to create a mysql docker container, and want my application to access the running mysql container instead of using host’s mysql. But I did not get success in this. My host machine is Oracle Ubuntu 18.04 VirtualBox.
Following are the things I am trying to to connect my application to mysql container:
- I created a bridge network in docker. named it my-net.
- Created mysql container using following command.
docker container run --name mysql-demo --network my-net -e MYSQL_ROOT_PASSWORD=MySQL_Num1 -e MYSQL_DATABASE=demographics -e MYSQL_USER=test -e MYSQL_PASSWORD=test1234 -d mysql:latest
Made sure the container is up and running. Also, the database ‘demographics’ is created in container’s mysql.
In SpringBoot’s application.properties used the connection parameters as below, instead of localhost I used the mysql container name:
- When I start the application, I get error: com.mysql.cj.jdbc.CommunicationException: Communications Link Failure