无法连接到在Docker容器中运行的oracledb

时间:2019-06-28 23:43:11

标签: oracle macos docker

Mac OS和docker 从oracledb控制台中,我无法以sys身份连接,我在oracle中键入的密码也无济于事

SQL> connect sys as sysdba;
Enter password: 
ERROR:
ORA-12547: TNS:lost contact

我是怎么做到的...

    docker pull absolutapps/oracle-12c-ee
    docker run -d --name oracle-12cR1-ee --privileged absolutapps/oracle-12c-ee
    docker logs -f oracle-12cR1-ee

到那时候我明白了

PL/SQL procedure successfully completed.

Please login to http://<ip_address>:8080/em to use enterprise manager
User: sys; Password oracle; Sysdba: true
Fixing permissions...
Running init scripts...
Init scripts in /oracle.init.d/: Ignoring /oracle.init.d/*

Done with scripts we are ready to go

我运行的下一条命令是

docker exec -it 28b0f34f7a81 bash -c "source /home/oracle/.bashrc; sqlplus /nolog"

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jun 28 23:08:41 2019


Copyright (c) 1982, 2014, Oracle.  All rights reserved.

SQL> connect sys as sysdba;
Enter password: 
ERROR:
ORA-12547: TNS:lost contact

在这一点上,我被困住了...

以前有没有想过?

1 个答案:

答案 0 :(得分:2)

看着source code for that image you're using,我可以看到他们正在使用gosu oracle sqlplus来以提升的特权连接到数据库,因此我在我的环境中尝试了这一点,似乎非常适合您需要:

docker exec -it oracle-12cR1-ee sh -c 'gosu oracle sqlplus "sys as sysdba"'

获取..

SQL*Plus: Release 12.1.0.2.0 Production on Sat Jun 29 00:33:12 2019

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Enter password: 

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> 

然后能够(例如):

SQL> SELECT USERNAME from SYS.ALL_USERS;

享受! ;)


编辑:

仅使用sqlplus / as sysdba也可以,所以应该是这样:

docker exec -it oracle-12cR1-ee sh -c 'gosu oracle sqlplus / as sysdba'