如何连接到docker Oracle实例

我正在按照这些说明 。

我已经创build了这样的docker容器:

docker run --name oracle \ -p 1521:1521 \ -e ORACLE_SID=ORASID \ -e ORACLE_PDB=ORAPDB \ -e ORACLE_PWD=F1f@f23_ \ -v /mnt_point/oradata:/home/oracle/oradata \ oracle/database:12.2.0.1-ee 

输出是:

 ######################### DATABASE IS READY TO USE! ######################### The following output is now a tail of the alert.log: Completed: alter pluggable database ORAPDB open 2017-08-07T19:16:31.190780+00:00 ORAPDB(3):CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/opt/oracle/oradata/ORASID/ORAPDB/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ORAPDB(3):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/opt/oracle/oradata/ORASID/ORAPDB/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ORAPDB(3):ALTER DATABASE DEFAULT TABLESPACE "USERS" ORAPDB(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS" 2017-08-07T19:16:32.867558+00:00 ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORASID/control01.ctl' SCOPE=SPFILE; ALTER PLUGGABLE DATABASE ORAPDB SAVE STATE Completed: ALTER PLUGGABLE DATABASE ORAPDB SAVE STATE 

我通过ctrl + c杀死它。 然后我运行:

 docker start oracle docker logs -f oracle ######################### DATABASE IS READY TO USE! ######################### The following output is now a tail of the alert.log: ORAPDB(3):Undo initialization finished serial:0 start:508498668 end:508498772 diff:104 ms (0.1 seconds) ORAPDB(3):Database Characterset for ORAPDB is AL32UTF8 ORAPDB(3):Opatch validation is skipped for PDB ORAPDB (con_id=0) 2017-08-07T19:25:39.799508+00:00 ORAPDB(3):Opening pdb with no Resource Manager plan active Pluggable database ORAPDB opened read write Starting background process CJQ0 Completed: ALTER DATABASE OPEN 2017-08-07T19:25:40.536753+00:00 CJQ0 started with pid=38, OS id=239 2017-08-07T19:25:42.538433+00:00 Shared IO Pool defaulting to 64MB. Trying to get it from Buffer Cache for process 77. =========================================================== Dumping current patch information =========================================================== No patches have been applied =========================================================== 

然后我尝试像这样连接:

 docker exec -ti oracle sqlplus pdbadmin@ORAPDB 

结果是:

 ORA-12154: TNS:could not resolve the connect identifier specified 

然后它问我一个用户名。 无论哪个用户SYS,SYSTEM或PDBADMIN,我都无法连接。 我已经多次重新input密码(F1f @ f23_),以确保它不是拼写错误。 任何想法,将不胜感激。

我也遇到过这些图片。 您必须首先打开可插拔数据库,然后才能连接到它。

我这样做是这样的:

 docker exec -ti oracle sqlplus / as sysdba alter pluggable database pdb1 open; 

一旦容器启动并创build数据库,就可以通过以下方法之一连接到任何其他数据库:

 1) sqlplus sys/<your password>@//localhost:1521/<your SID> as sysdba 2) sqlplus system/<your password>@//localhost:1521/<your SID> 3) sqlplus pdbadmin/<your password>@//localhost:1521/<Your PDB name> 

在Docker容器中运行SQL * Plus

你可以使用你用来启动数据库的同一个Docker镜像,运行sqlplus来连接它,例如:

 docker run --rm -ti oracle/database:12.2.0.1-ee sqlplus pdbadmin/<yourpassword>@//<db-container-ip>:1521/ORCLPDB1 

另一个select是使用docker exec并在已经运行数据库的同一个容器中运行sqlplus:

 docker exec -ti <container name> sqlplus pdbadmin@ORCLPDB1 

要运行Oracle数据库Docker镜像,请使用docker run命令,如下所示:

 docker run --name <container name> \ -p <host port>:1521 -p <host port>:5500 \ -e ORACLE_SID=<your SID> \ -e ORACLE_PDB=<your PDB name> \ -e ORACLE_PWD=<your database passwords> \ -e ORACLE_CHARACTERSET=<your character set> \ -v [<host mount point>:]/opt/oracle/oradata \ oracle/database:12.2.0.1-ee Parameters: --name: The name of the container (default: auto generated) -p: The port mapping of the host port to the container port. Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express) -e ORACLE_SID: The Oracle Database SID that should be used (default: ORCLCDB) -e ORACLE_PDB: The Oracle Database PDB name that should be used (default: ORCLPDB1) -e ORACLE_PWD: The Oracle Database SYS, SYSTEM and PDB_ADMIN password (default: auto generated) -e ORACLE_CHARACTERSET: The character set to use when creating the database (default: AL32UTF8) -v /opt/oracle/oradata The data volume to use for the database. Has to be owned by the Unix user "oracle" or set appropriately. If omitted the database will not be persisted over container recreation. -v /opt/oracle/scripts/startup | /docker-entrypoint-initdb.d/startup Optional: A volume with custom scripts to be run after database startup. For further details see the "Running scripts after setup and on startup" section below. -v /opt/oracle/scripts/setup | /docker-entrypoint-initdb.d/setup Optional: A volume with custom scripts to be run after database setup. For further details see the "Running scripts after setup and on startup" section below. 

有用的: https : //github.com/oracle/docker-images/tree/master/OracleDatabase