简体   繁体   中英

Want to run mysql from Docker and connect with springboot

I continuously face the error:

 Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure 
 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server
Caused by: java.net.UnknownHostException: No such host is known (mysql-standalone)

At first I create database from docker with the code:

docker run --name mysql-standalone -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=digitalprofile -e MYSQL_USER=sa -e MYSQL_PASSWORD=password mysql:5.6

After running it container is up

docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS               NAMES
80584bfdf76c        mysql:5.6           "docker-entrypoint.s…"   23 minutes ago      Up 23  minutes       3306/tcp            mysql-standalone

In appilcation.properties in eclipse

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://mysql-standalone:3306/digitalprofile
spring.datasource.username=sa
spring.datasource.password=password
server.port=9090

spring.datasource.url=jdbc:mysql://localhost or ip address?:3306/digitalprofile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM