我相对较不熟悉部署。我有一个预先存在的连接到MySQL数据库的Spring Boot应用程序,我也正在使用Flyway作为数据库迁移工具。
以下是application.properties的内容:
spring.jpa.hibernate.ddl-auto=update
management.endpoint.health.show-details=always
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# Running in container
spring.datasource.url=jdbc:mysql://mysql-standalone:3306/db-name
spring.datasource.username=root
spring.datasource.password=root
flyway.user=root
flyway.password=root
flyway.schemas=db-name
spring.flyway.baseline-on-migrate=true
spring.flyway.check-location =true
最近我对应用程序进行了docker处理-> docker-compose.yml
:
version: '3'
services:
mysql-standalone:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=db-name
- MYSQL_USER=root
- MYSQL_PASSWORD=root
volumes:
- my-app:/var/lib/mysql
spring-boot:
image: my-app
ports:
[8080:8080]
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysql-standalone
volumes:
my-app:
这在运行docker-compose up
接下来我要做的是使用以下命令在heroku上部署此容器:
heroku login
heroku container:login
heroku container:push web
heroku container:release web
但是,由于以下错误,该应用程序继续崩溃:
2020-10-22T11:34:43.143365+00:00 app[web.1]: at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spri
ng-context-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
2020-10-22T11:34:43.143365+00:00 app[web.1]: at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationC
ontext.java:869) ~[spring-context-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
2020-10-22T11:34:43.143366+00:00 app[web.1]: at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[sprin
g-context-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
2020-10-22T11:34:43.143366+00:00 app[web.1]: at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplication
Context.java:143) ~[spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
2020-10-22T11:34:43.143366+00:00 app[web.1]: at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.4.RELEASE.jar!/:2.
3.4.RELEASE]
2020-10-22T11:34:43.143367+00:00 app[web.1]: at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.4.RELEASE.jar!/:2.
3.4.RELEASE]
2020-10-22T11:34:43.143367+00:00 app[web.1]: at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.4.RELEASE.j
ar!/:2.3.4.RELEASE]
2020-10-22T11:34:43.143367+00:00 app[web.1]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.4.RELEASE.jar!/:2.3.4.
RELEASE]
2020-10-22T11:34:43.143368+00:00 app[web.1]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.4.RELEASE.jar!/:2.3.4
.RELEASE]
2020-10-22T11:34:43.143372+00:00 app[web.1]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.4.RELEASE.jar!/:2.3.4
.RELEASE]
2020-10-22T11:34:43.143373+00:00 app[web.1]: at com.rhr.imageclassificationbackend.ImageclassificationbackendApplication.main(ImageclassificationbackendApplication
.java:30) ~[classes!/:0.0.1-SNAPSHOT]
2020-10-22T11:34:43.143373+00:00 app[web.1]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
2020-10-22T11:34:43.143374+00:00 app[web.1]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
2020-10-22T11:34:43.143374+00:00 app[web.1]: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
2020-10-22T11:34:43.143374+00:00 app[web.1]: at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
2020-10-22T11:34:43.143375+00:00 app[web.1]: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[imageClassificationMicroservice.ja
r:0.0.1-SNAPSHOT]
2020-10-22T11:34:43.143375+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:107) ~[imageClassificationMicroservice.jar:0.0.1-SNAP
SHOT]
2020-10-22T11:34:43.143375+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[imageClassificationMicroservice.jar:0.0.1-SNAPS
HOT]
2020-10-22T11:34:43.143376+00:00 app[web.1]: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[imageClassificationMicroservice.jar:0.0.1-S
NAPSHOT]
2020-10-22T11:34:43.143376+00:00 app[web.1]: Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
2020-10-22T11:34:43.143377+00:00 app[web.1]: Unable to obtain connection from database: Communications link failure
2020-10-22T11:34:43.143377+00:00 app[web.1]:
2020-10-22T11:34:43.143377+00:00 app[web.1]: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from t
he server.
2020-10-22T11:34:43.143377+00:00 app[web.1]: ----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
2020-10-22T11:34:43.143378+00:00 app[web.1]: SQL State : 08S01
2020-10-22T11:34:43.143378+00:00 app[web.1]: Error Code : 0
2020-10-22T11:34:43.143378+00:00 app[web.1]: Message : Communications link failure
2020-10-22T11:34:43.143379+00:00 app[web.1]:
2020-10-22T11:34:43.143379+00:00 app[web.1]: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from t
he server.
2020-10-22T11:34:43.143380+00:00 app[web.1]:
2020-10-22T11:34:43.143380+00:00 app[web.1]: at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:65) ~[flyway-core-6.4.4.jar!/:na]
2020-10-22T11:34:43.143380+00:00 app[web.1]: at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:80) ~[flyway-core-6.4.4.jar
!/:na]
2020-10-22T11:34:43.143381+00:00 app[web.1]: at org.flywaydb.core.Flyway.execute(Flyway.java:456) ~[flyway-core-6.4.4.jar!/:na]
2020-10-22T11:34:43.143381+00:00 app[web.1]: at org.flywaydb.core.Flyway.migrate(Flyway.java:159) ~[flyway-core-6.4.4.jar!/:na]
2020-10-22T11:34:43.143382+00:00 app[web.1]: at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitiali
zer.java:65) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
2020-10-22T11:34:43.143382+00:00 app[web.1]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapa
bleBeanFactory.java:1853) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
2020-10-22T11:34:43.143382+00:00 app[web.1]: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapable
BeanFactory.java:1790) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
2020-10-22T11:34:43.143383+00:00 app[web.1]: ... 27 common frames omitted
2020-10-22T11:34:43.143383+00:00 app[web.1]: Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
2020-10-22T11:34:43.143383+00:00 app[web.1]:
2020-10-22T11:34:43.143384+00:00 app[web.1]: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from t
he server.
2020-10-22T11:34:43.143384+00:00 app[web.1]: at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.1
6.jar!/:8.0.16]
2020-10-22T11:34:43.143384+00:00 app[web.1]: at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connecto
r-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143385+00:00 app[web.1]: at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143385+00:00 app[web.1]: at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143385+00:00 app[web.1]: at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143385+00:00 app[web.1]: at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar!/:8
.0.16]
2020-10-22T11:34:43.143386+00:00 app[web.1]: at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143386+00:00 app[web.1]: at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143389+00:00 app[web.1]: at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143390+00:00 app[web.1]: at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143390+00:00 app[web.1]: at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143390+00:00 app[web.1]: at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143391+00:00 app[web.1]: at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.5.jar!/:na]
2020-10-22T11:34:43.143391+00:00 app[web.1]: at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) ~[flyway-core-6.4.4.jar!/:na]
2020-10-22T11:34:43.143392+00:00 app[web.1]: ... 33 common frames omitted
2020-10-22T11:34:43.143392+00:00 app[web.1]: Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
2020-10-22T11:34:43.143392+00:00 app[web.1]:
2020-10-22T11:34:43.143393+00:00 app[web.1]: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from t
he server.
2020-10-22T11:34:43.143393+00:00 app[web.1]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
2020-10-22T11:34:43.143393+00:00 app[web.1]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[n
a:na]
2020-10-22T11:34:43.143394+00:00 app[web.1]: at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java
:45) ~[na:na]
2020-10-22T11:34:43.143394+00:00 app[web.1]: at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
2020-10-22T11:34:43.143395+00:00 app[web.1]: at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.ja
r!/:8.0.16]
2020-10-22T11:34:43.143395+00:00 app[web.1]: at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.16.j
ar!/:8.0.16]
2020-10-22T11:34:43.143396+00:00 app[web.1]: at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.16.j
ar!/:8.0.16]
2020-10-22T11:34:43.143396+00:00 app[web.1]: at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector
-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143396+00:00 app[web.1]: at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.1
6.jar!/:8.0.16]
2020-10-22T11:34:43.143397+00:00 app[web.1]: at com.mysql.cj.NativeSession.connect(NativeSession.java:152) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143397+00:00 app[web.1]: at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) ~[mysql-connector-java-8.0.16.jar!/:8.0
.16]
2020-10-22T11:34:43.143397+00:00 app[web.1]: at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
2020-10-22T11:34:43.143397+00:00 app[web.1]: ... 44 common frames omitted
2020-10-22T11:34:43.143398+00:00 app[web.1]: Caused by: java.net.UnknownHostException: mysql-standalone: Name or service not known
2020-10-22T11:34:43.143398+00:00 app[web.1]: at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
2020-10-22T11:34:43.143398+00:00 app[web.1]: at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929) ~[na:na]
2020-10-22T11:34:43.143399+00:00 app[web.1]: at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515) ~[na:na]
2020-10-22T11:34:43.143399+00:00 app[web.1]: at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848) ~[na:na]
2020-10-22T11:34:43.143399+00:00 app[web.1]: at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505) ~[na:na]
2020-10-22T11:34:43.143399+00:00 app[web.1]: at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364) ~[na:na]
2020-10-22T11:34:43.143400+00:00 app[web.1]: at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298) ~[na:na]
2020-10-22T11:34:43.143400+00:00 app[web.1]: at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) ~[mysql-connector-java-8.0.16.j
ar!/:8.0.16]
2020-10-22T11:34:43.143400+00:00 app[web.1]: at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.1
6.jar!/:8.0.16]
2020-10-22T11:34:43.143401+00:00 app[web.1]: ... 47 common frames omitted
2020-10-22T11:34:43.143401+00:00 app[web.1]:
2020-10-22T11:34:43.348389+00:00 heroku[web.1]: Process exited with status 1
2020-10-22T11:34:43.405937+00:00 heroku[web.1]: State changed from starting to crashed