无法在Docker内部的Spring Boot应用程序中访问RDS

时间:2019-03-15 06:51:19

标签: spring spring-boot docker amazon-rds

我想对我的spring boot应用程序进行docker化。我用

docker build -t <Name> .

构建我的项目,然后尝试运行它。但是我的spring boot应用程序出现Communication link失败,无法连接到rds数据库。我在属性文件中正确设置了数据库URL,并且我的应用程序与RDS位于同一VPC中。我的docker文件是:

FROM maven:3.5.2-jdk-8-alpine AS MAVEN_TOOL_CHAIN
COPY pom.xml /tmp/
WORKDIR /tmp/
RUN mvn verify clean --fail-never
COPY src /tmp/src/
RUN mvn package -DskipTests

FROM tomcat:8.0.51-jre8-alpine
COPY --from=MAVEN_TOOL_CHAIN /tmp/target/<ProjectName>.war $CATALINA_HOME/webapps/<ProjectName>.war
COPY ./conf/* $CATALINA_HOME/conf/
CMD ["catalina.sh","run"]

我得到的错误的堆栈跟踪如下:

2019-03-14 14:17:03.400  WARN 1 --- [pool-3-thread-1] o.h.e.j.s.SqlExceptionHelper             : SQL Error: 0, SQLState: 08S01

2019-03-14 14:17:03.400 ERROR 1 --- [pool-3-thread-1] o.h.e.j.s.SqlExceptionHelper             : 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.
2019-03-14 14:17:03.400  INFO 1 --- [pool-3-thread-1] c.d.c.s.c.CampaignAnalyticsService       : error in updating analytics Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
2019-03-14 14:17:03.400  INFO 1 --- [pool-3-thread-1] c.d.c.s.c.CampaignAnalyticsService       : [543, Send, Announcement, -, Sukhna:, Run, for, fun]
2019-03-14 14:17:03.401  INFO 1 --- [pool-3-thread-1] c.z.h.HikariDataSource                   : HikariPool-1 - Starting...
2019-03-14 14:17:04.402 ERROR 1 --- [pool-3-thread-1] c.z.h.p.HikariPool                       : HikariPool-1 - Exception during pool initialization.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.

我使用以下命令来运行我的映像:

docker run -p 8081:8000 <Name>

0 个答案:

没有答案