Я не знаю, как настроить сетевое свойство в файле docker-compose.yml, после использования docker-compose, проект запускается, но не может подключиться к базе данных, посмотреть конфигурацию других людей, Добавленотег ссылки, но будет сообщение об ошибке, записи последовательности здесь не разрешены.
springboot, msyql5.7
dockercompose.yml
version : '3'
services:
mysql:
container_name: mysql-compose
image: mysql:5.7
environment:
MYSQL_DATABASE: aurora1
MYSQL_ROOT_PASSWORD: 123456789
MYSQL_ROOT_HOST: '%'
networks:
- spring-demo-network
ports:
- "6665:3306"
restart: always
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--default-time-zone=+8:00'
]
app:
container_name: backend-compose
build:
context: .
dockerfile: Dockerfile
restart: always
volumes:
- .:/vol/development
ports:
- "8088:8088"
networks:
- spring-demo-network
depends_on:
- mysql
networks:
spring-demo-network:
driver: bridge
Конфигурация в проекте springboot:
datasource:
url: jdbc:mysql://localhost:3306/aurora?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
username: root
password: 123456789
driverClassName: com.mysql.jdbc.Driver
backend-compose | 19-06-07 08:09:02.165 [main] WARN : c.z.hikari.util.DriverDataSource.<init> - Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
backend-compose | 19-06-07 08:09:03.324 [main] ERROR : com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException - HikariPool-1 - Exception during pool initialization.
backend-compose | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
backend-compose |
backend-compose | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
backend-compose | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
backend-compose | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
backend-compose | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
backend-compose | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
backend-compose | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
backend-compose | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
backend-compose | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
backend-compose | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
backend-compose | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
backend-compose | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
backend-compose | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
backend-compose | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
backend-compose | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
backend-compose | at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:302)
backend-compose | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
backend-compose | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
backend-compose | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
backend-compose | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
backend-compose | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
backend-compose | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
backend-compose | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
backend-compose | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
backend-compose | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
backend-compose | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
backend-compose | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)
backend-compose | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:853)
backend-compose | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
backend-compose | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
backend-compose | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
backend-compose | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
backend-compose | at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
backend-compose | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
backend-compose | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
backend-compose | at com.aurora.backend.Application.main(Application.java:19)
backend-compose | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
backend-compose | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
backend-compose | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
backend-compose | at java.lang.reflect.Method.invoke(Method.java:498)
backend-compose | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
backend-compose | at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
backend-compose | at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
backend-compose | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
backend-compose | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
backend-compose |