Spring boot 将Spring boot应用程序连接到Docker容器中的Oracle数据库12.2.0.1
我有Oracle数据库作为Docker容器运行,下面是容器的详细信息Spring boot 将Spring boot应用程序连接到Docker容器中的Oracle数据库12.2.0.1,spring-boot,docker,oracle12c,flyway,connection-timeout,Spring Boot,Docker,Oracle12c,Flyway,Connection Timeout,我有Oracle数据库作为Docker容器运行,下面是容器的详细信息 Config: { "Hostname": "8ad016675bd2", "Domainname": "", "User": "oracle", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "ExposedPorts": {
Config: {
"Hostname": "8ad016675bd2",
"Domainname": "",
"User": "oracle",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"1521/tcp": {},
"5500/tcp": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1",
"ORACLE_SID=ORCL"
],
"Cmd": [
"/bin/sh",
"-c",
"/bin/bash /home/oracle/setup/dockerInit.sh"
],
"Healthcheck": {
"Test": [
"CMD-SHELL",
"/bin/bash /home/oracle/setup/healthcheck.sh"
],
"Interval": 60000000000,
"Timeout": 10000000000
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c13a0ee218e9245d7916c7ffb078adf4191a14e100221274f3125975fc6cb5b7",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"1521/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "32773"
}
],
"5500/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "32772"
}
]
},
"SandboxKey": "/var/run/docker/netns/c13a0ee218e9",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "782fa0c989db7f58643416fea7b60165ad00ce3067b7bb7a6af72c0619c31e5a",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "486e58b051b36eb20838e5f9edcb6fe205407e583e75fedf86460ecec41dd9c5",
"EndpointID": "782fa0c989db7f58643416fea7b60165ad00ce3067b7bb7a6af72c0619c31e5a",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
我正在尝试使用以下凭据通过Flyway连接到oracle数据库
spring.jpa.database=oracle
spring.datasource.url=jdbc:oracle:thin:@172.17.0.2:32773/ORCLPDB1
spring.datasource.username=sys
spring.datasource.password=Oradoc_db1
但我有以下错误
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:523) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:521) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:660) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:286) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
... 35 common frames omitted
Caused by: java.io.IOException: Connection timed out: connect, socket connect lapse 21030 ms. /172.17.0.2 32773 30000 1 true
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:209) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.nt.ConnOption.connect(ConnOption.java:161) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:470) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
... 40 common frames omitted
Unable to obtain connection from database: IO Error: The Network Adapter
could not establish the connection
----------------------------------------------------------------------------
-------------------------------
SQL State : 08006
Error Code : 17002
Message : IO Error: The Network Adapter could not establish the
connection
有人能指出我这里遗漏了什么吗?以及如何解决此问题。首先,您需要检查容器为1521/tcp端口公开的正确端口:
docker port your_containerID 1521/tcp
然后确保容器中的数据库已启动:
docker ps
(*在容器状态不正常时检查)
1.-与sqlplus连接
docker exec -it your_containerID bash -c "source /home/oracle/.bashrc; sqlplus /nolog"
2.-使用SQL Developer IDE等连接jdbc并创建方案:
create user "MYUSER" identified by admin123 default tablespace "USERS" temporary tablespace "TEMP";
grant "DBA" to "MYUSER";
grant "RESOURCE" to "MYUSER";
grant SELECT ANY DICTIONARY to "MYUSER";
grant CREATE SEQUENCE to "MYUSER";
grant CREATE SYNONYM to "MYUSER";
grant CREATE SESSION to "MYUSER";
grant CREATE TYPE to "MYUSER";
grant CREATE PROCEDURE to "MYUSER";
grant CREATE DATABASE LINK to "MYUSER";
grant CREATE ANY DIRECTORY to "MYUSER";
grant CREATE TABLE to "MYUSER";
grant EXPORT FULL DATABASE to "MYUSER";
grant UNLIMITED TABLESPACE to "MYUSER";
grant CREATE JOB to "MYUSER";
grant CREATE VIEW to "MYUSER";
grant ALTER SESSION to "MYUSER";
grant EXECUTE on "SYS"."SYS_PLSQL_FAA5F685_2385_1" to "MYUSER";
grant EXECUTE on "SYS"."SYS_PLSQL_D9B1149D_9_1" to "MYUSER";
最后一步是application.yml:
datasource:
username: MYUSER
password: admin123
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@(description=(address=(host=your_docker_ip)(protocol=tcp)(port=your_port_number))(connect_data=(service_name=ORCLPDB1.localdomain)))
首先,您需要检查容器为1521/tcp端口公开的正确端口:
docker port your_containerID 1521/tcp
然后确保容器中的数据库已启动:
docker ps
(*在容器状态不正常时检查)
1.-与sqlplus连接
docker exec -it your_containerID bash -c "source /home/oracle/.bashrc; sqlplus /nolog"
2.-使用SQL Developer IDE等连接jdbc并创建方案:
create user "MYUSER" identified by admin123 default tablespace "USERS" temporary tablespace "TEMP";
grant "DBA" to "MYUSER";
grant "RESOURCE" to "MYUSER";
grant SELECT ANY DICTIONARY to "MYUSER";
grant CREATE SEQUENCE to "MYUSER";
grant CREATE SYNONYM to "MYUSER";
grant CREATE SESSION to "MYUSER";
grant CREATE TYPE to "MYUSER";
grant CREATE PROCEDURE to "MYUSER";
grant CREATE DATABASE LINK to "MYUSER";
grant CREATE ANY DIRECTORY to "MYUSER";
grant CREATE TABLE to "MYUSER";
grant EXPORT FULL DATABASE to "MYUSER";
grant UNLIMITED TABLESPACE to "MYUSER";
grant CREATE JOB to "MYUSER";
grant CREATE VIEW to "MYUSER";
grant ALTER SESSION to "MYUSER";
grant EXECUTE on "SYS"."SYS_PLSQL_FAA5F685_2385_1" to "MYUSER";
grant EXECUTE on "SYS"."SYS_PLSQL_D9B1149D_9_1" to "MYUSER";
最后一步是application.yml:
datasource:
username: MYUSER
password: admin123
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@(description=(address=(host=your_docker_ip)(protocol=tcp)(port=your_port_number))(connect_data=(service_name=ORCLPDB1.localdomain)))
我猜oracle是在1521年从容器中暴露出来的,而您正试图连接32773。请确认神谕在32773?@BalajiSrinivasan端口号中暴露的端口是否正常。运行
docker-port
命令会给出1521/tcp->0.0.0.0:32773 5500/tcp->0.0.0.0:32772
您是否能够通过任何SQL客户端连接到oracle?我猜oracle是从1521中的容器中暴露出来的,您正在尝试连接32773。请确认神谕在32773?@BalajiSrinivasan端口号中暴露的端口是否正常。运行docker-port
命令将给出1521/tcp->0.0.0.0:32773 5500/tcp->0.0.0.0:32772
您是否能够通过任何SQL客户端连接到oracle?