我有作为Docker容器运行的Oracle数据库,下面是容器的详细信息。
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
有人可以指出我在这里缺少什么吗?以及解决方法。
答案 0 :(得分:0)
首先,您需要检查容器暴露的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";
应用程序的最后一步。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)))