简体   繁体   English

如何使用Tomcat托管的Spring Boot应用程序从Docker Container通过JDBC访问Oracle AWS RDS

[英]How to access Oracle AWS RDS through JDBC from Docker Container with Spring boot application hosted on Tomcat

I am currently running a WAR file within an Apache Tomcat Docker container. 我当前在Apache Tomcat Docker容器中运行WAR文件。 The war file is a Spring Boot Application. war文件是一个Spring Boot应用程序。 The application.properties contain a connection using oracle jdbc6 connection to the database. application.properties包含使用oracle jdbc6连接到数据库的连接。 The jar file is included in the Maven build. jar文件包含在Maven构建中。 I continue to receive a 500. I can run the same WAR file on my local machine and all connections work fine. 我继续收到500。我可以在本地计算机上运行相同的WAR文件,并且所有连接工作正常。 That is why I am assuming its because of open ports on the docker container. 这就是为什么我假设它是因为docker容器上的开放端口。

sudo docker run -d -p 8080:8080 -p 1521:1521  --restart unless-stopped fd13ad9f3e16

I opened the ports up for 1521 but still cannot access the database. 我为1521打开了端口,但仍然无法访问数据库。

Is there anything else I need to run on my docker container in order to access the Oracle JDBC connection outside? 为了访问外部的Oracle JDBC连接,我还需要在docker容器上运行其他任何东西吗?

So here are the steps I took in AWS to make sure that this is working on my Tomcat Docker instances for JDBC connection. 因此,这是我在AWS中采取的步骤,以确保该方法适用于我的Tomcat Docker实例以进行JDBC连接。 You do not need to run -p 1521:1521 since the docker container is only a Tomcat instance and not hosting Oracle. 您不需要运行-p 1521:1521,因为docker容器只是一个Tomcat实例,而不是托管Oracle。 Make sure you set the application.properties file (below is an example) 确保设置了application.properties文件(以下为示例)

spring.datasource.url=jdbc:oracle:thin:@//< DNS name for RDS>:1521/<SID>
spring.datasource.username=<oracle db username>
spring.datasource.password=< oracle db password for username>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
#hibernate config
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
#spring.data.rest.base-path=/api
spring.data.rest.default-page-size: 20

Next, make sure that your RDS security group is set up to allow the specific IP address of your EC2 instances. 接下来,确保将RDS安全组设置为允许EC2实例的特定IP地址。 I would not recommend opening up to all. 我不建议向所有人开放。

Next, make sure to open up the security group for the EC2 instance for 1521. 接下来,确保为1521打开EC2实例的安全组。

That should be it. 应该是这样。 The problem I was having was with the RDS security group not be specifically configured for my EC2 instance. 我遇到的RDS安全组问题没有为我的EC2实例专门配置。

You can also install SQLplus using RPM packages from Oracle to test your connection as well. 您也可以使用Oracle的RPM软件包安装SQLplus,以测试您的连接。 Example command would be: 示例命令为:

sqlplus '<username>/<password>@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=<aws DNS name>)(Port=1521))(CONNECT_DATA=(SID=<name of SID>)))'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Spring Boot 应用程序访问 postgres docker 容器 - Access postgres docker container with spring boot application 如何从不同的 docker 容器中读取 spring 启动应用程序属性? - How to read spring boot application properties from a different docker container? 带有RDS的AWS EB上的Spring Boot应用程序部署 - Deployment of a spring boot application on AWS EB with RDS 如何在Heroku中将Oracle jdbc数据库客户端添加到Spring引导应用程序中? - How to add Oracle jdbc database client to Spring boot application in Heroku? 在AWS Elastic BeanStalk上运行的Spring Boot应用程序中配置AWS RDS - Configuring AWS RDS in a Spring Boot Application running on AWS Elastic BeanStalk 无法访问EBS上托管的Spring Boot应用程序 - Unable to access spring boot application hosted on EBS 在docker容器中重新部署spring-boot应用程序? - Redeploy spring-boot application in docker container? Spring启动应用程序在IntelliJ中工作,但不是Docker容器 - Spring boot application working in IntelliJ, but not as Docker Container 持续向AWS托管的Spring Boot应用程序部署功能 - Continuously deploying features to Spring Boot application hosted by AWS 无法从本地Spring Boot连接AWS RDS - Can't connect AWS RDS from local Spring boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM