如何连接到 docker Oracle 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45554498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I connect to docker Oracle instance
提问by Chuck
I am following these instructions.
我正在遵循这些说明。
I have created a docker container like this:
我创建了一个这样的 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
The output is:
输出是:
#########################
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
I kill it via ctrl+c. I then run:
我通过 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
===========================================================
I then attempt to connect like this:
然后我尝试像这样连接:
docker exec -ti oracle sqlplus pdbadmin@ORAPDB
The result is:
结果是:
ORA-12154: TNS:could not resolve the connect identifier specified
It then asks me for a username. Regardless of which user SYS, SYSTEM or PDBADMIN, I cannot connect. I have retyped the password (F1f@f23_) a multitude of times to make sure it was not a typo. Any thoughts on this would be appreciated.
然后它要求我输入用户名。无论是SYS、SYSTEM还是PDBADMIN用户,我都无法连接。我已经多次重新输入密码 (F1f@f23_) 以确保它不是打字错误。对此的任何想法将不胜感激。
采纳答案by William Friesen
I've encountered this with those images, too. You will first have to open the pluggable database before you can connect to it.
我也遇到过这些图像。您必须先打开可插拔数据库,然后才能连接到它。
I do that with something like this:
我这样做是这样的:
docker exec -ti oracle sqlplus / as sysdba
alter pluggable database pdb1 open;
回答by Peter Teoh
Yes, I got the same error after setting up Oracle database in docker too.
是的,我在 docker 中设置 Oracle 数据库后也遇到了同样的错误。
So first check the instance is running (and look for the ORACLE_SID):
所以首先检查实例是否正在运行(并查找 ORACLE_SID):
The Oracle SID is ORCLCDB.
Oracle SID 是 ORCLCDB。
If you don't have the environment set for ORACLE_SID, you get:
如果您没有为 ORACLE_SID 设置环境,您将获得:
Connection failed.
连接失败。
But after you set your ORACLE_SID:
但是在您设置 ORACLE_SID 之后:
And now you no longer get the connection failure error, but a different SYSDBA instead.
现在您不再收到连接失败错误,而是收到不同的 SYSDBA。
Just add "/ as sysdba" to your entire sqlplus command and you are good to go.
只需在整个 sqlplus 命令中添加“/ as sysdba”即可。
回答by Annie C
This instruction worked for me:
这条指令对我有用:
Starting SQL*Plus and Connecting to the Database
https://docs.oracle.com/database/121/ADMQS/GUID-DE8A79BD-FAE4-4364-98FF-D2BD992A06E7.htm#ADMQS0361
启动 SQL*Plus 并连接到数据库
https://docs.oracle.com/database/121/ADMQS/GUID-DE8A79BD-FAE4-4364-98FF-D2BD992A06E7.htm#ADMQS0361
Basically get into the oracle container, then enter sqlplus. type SYS AS SYSDBA at the user name prompt, and then password. After that, I create the user and tables.
基本进入oracle容器,然后进入sqlplus。在用户名提示下输入 SYS AS SYSDBA,然后输入密码。之后,我创建用户和表。
回答by Ikrom
Once the container has been started and the database created you can connect to it just like to any other database by one of the following methods:
一旦容器启动并创建了数据库,您就可以像连接任何其他数据库一样通过以下方法之一连接到它:
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>
Running SQL*Plus in a Docker container
在 Docker 容器中运行 SQL*Plus
You may use the same Docker image you used to start the database, to run sqlplus to connect to it, for example:
您可以使用与启动数据库相同的 Docker 映像,运行 sqlplus 以连接到它,例如:
docker run --rm -ti oracle/database:12.2.0.1-ee sqlplus pdbadmin/<yourpassword>@//<db-container-ip>:1521/ORCLPDB1
Another option is to use docker exec and run sqlplus from within the same container already running the database:
另一种选择是使用 docker exec 并从已经运行数据库的同一个容器中运行 sqlplus:
docker exec -ti <container name> sqlplus pdbadmin@ORCLPDB1
To run your Oracle Database Docker image use the docker run command as follows:
要运行您的 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.
useful: https://github.com/oracle/docker-images/tree/master/OracleDatabase
有用:https: //github.com/oracle/docker-images/tree/master/OracleDatabase