can not connect to oracledb running in a docker container - oracle

Mac OS and docker
From the oracledb console, I can not connect as sys, password I type in oracle and no go
SQL> connect sys as sysdba;
Enter password:
ERROR:
ORA-12547: TNS:lost contact
how did I get this far...
docker pull absolutapps/oracle-12c-ee
docker run -d --name oracle-12cR1-ee --privileged absolutapps/oracle-12c-ee
docker logs -f oracle-12cR1-ee
at then end of that I get
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
Next command I run is
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
at this point, I am stuck...
Thoughts or seen this before?

Looking at the source code for that image you're using I was able to see that they're using gosu oracle sqlplus to connect to the database with elevated privileges, so I tried this in my environment and seems to fit perfectly to what you need:
docker exec -it oracle-12cR1-ee sh -c 'gosu oracle sqlplus "sys as sysdba"'
getting..
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>
and then being able to (for example):
SQL> SELECT USERNAME from SYS.ALL_USERS;
Enjoy! ;)
Edit:
Using just sqlplus / as sysdba also works as well, so it would be:
docker exec -it oracle-12cR1-ee sh -c 'gosu oracle sqlplus / as sysdba'

Related

How to find default password of official Oracle database 21c (images) what run inside docker?

I run
docker pull container-registry.oracle.com/database/enterprise:latest
docker run -d --name oracle-db container-registry.oracle.com/database/enterprise:21.3.0.0
docker logs oracle-db
log
C:\Users\fffdfd>docker logs oracle-db
[2022:09:15 03:28:08]: Acquiring lock .ORCLCDB.create_lck with heartbeat 30 secs
[2022:09:15 03:28:08]: Lock acquired
[2022:09:15 03:28:08]: Starting heartbeat
[2022:09:15 03:28:08]: Lock held .ORCLCDB.create_lck
ORACLE EDITION: ENTERPRISE
LSNRCTL for Linux: Version 21.0.0.0.0 - Production on 15-SEP-2022 03:28:08
Copyright (c) 1991, 2021, Oracle. All rights reserved.
Starting /opt/oracle/product/21c/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 21.0.0.0.0 - Production
System parameter file is /opt/oracle/homes/OraDB21Home1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/3ffbbd06854e/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 21.0.0.0.0 - Production
Start Date 15-SEP-2022 03:28:09
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/homes/OraDB21Home1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/3ffbbd06854e/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully
Prepare for db operation
8% complete
Copying database files
C:\Users\fffdfd>docker exec oracle-db ./setPassword.sh 12345678
The Oracle base remains unchanged with value /opt/oracle
SQL*Plus: Release 21.0.0.0.0 - Production on Thu Sep 15 03:29:55 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
SQL> ALTER USER SYS IDENTIFIED BY "12345678"
*
ERROR at line 1:
ORA-01109: database not open
SQL> ALTER USER SYSTEM IDENTIFIED BY "12345678"
*
ERROR at line 1:
ORA-01109: database not open
SQL> ERROR:
ORA-65011: Pluggable database ORCLPDB1 does not exist.
SQL> ALTER USER PDBADMIN IDENTIFIED BY "12345678"
*
ERROR at line 1:
ORA-01109: database not open
SQL> Disconnected from Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
C:\Users\fffdfd>
Reference document at https://container-registry.oracle.com/ords/f?p=113:4:6576055923728:::4:P4_REPOSITORY,AI_REPOSITORY,AI_REPOSITORY_NAME,P4_REPOSITORY_NAME,P4_EULA_ID,P4_BUSINESS_AREA_ID:9,9,Oracle%20Database%20Enterprise%20Edition,Oracle%20Database%20Enterprise%20Edition,1,0&cs=3JV3L51pi5D5R69u0j2JIq9bovtnbkAkvZz0_bP7Tu1zHiE-Z_0Nrw_Cqh3q1gdQ5peQaDVEO2_JXEXQ0D_p_jA said
Note: Refer to the section titled "Changing the Default Password for
SYS User" to obtain the password.
but I don't see this. How to find default password of official Oracle database 21c (images) what run inside docker?
Reference document was wrong. Manual set password for user sys when create docker container, for example
docker run -d --name vyora -p 1521:1521 -p 5500:5500 -e ORACLE_SID=vyora -e ORACLE_PDB=vypdb -e ORACLE_PWD=12345678 -e INIT_SGA_SIZE=2000 -e INIT_PGA_SIZE=1000 -e ORACLE_EDITION=ee-or-se-database-edition -e ORACLE_CHARACTERSET=AL32UTF8 -e ENABLE_ARCHIVELOG=true -v "D:\oracle":/opt/oracle/oradata container-registry.oracle.com/database/enterprise:21.3.0.0
passowrd is 12345678 .
See https://docs.oracle.com/en/database/oracle/oracle-database/21/deeck/index.html#DEEDK-GUID-6589D4A1-14F3-42B3-8461-C9A7B840D148

SQL*Plus issues with connection to DB from Command Prompt

I am on SQL*Plus: Release 21.0.0.0.0, on a Windows machine.
In the command prompt, when I do
C:\users\TOMMY> sqlplus /nolog
I see this
SQL>
Here I connect to the Database using a connection string(EZ Connect format)
With Credentials,
username -> dddd
pwd -> wefm#vrev
host -> local
port -> 15210
ServiceName -> abcd.xysp.gthe.com
SQL> connect dddd/"wefm#vrev"#local:15210/abcd.xysp.gthe.com
And I see Output(after a few seconds),
Connected.
My issue begins when I decide to connect from Windows directly with sqlplus. Mentioned below
C:\users\TOMMY> sqlplus -S
dddd/"wefm#vrev"#local:15210/abcd.xysp.gthe.com
Results in an error, I am baffled. What am I missing
ERROR: ORA-12154: TNS:could not resolve the connect identifier
specified
I have also tried putting the connection string in single quotes (').
When I do that I get this whole thing printed out, which I assume is indicative of me passing the wrong args.
SQL*Plus: Release 21.0.0.0.0 - Production Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Use SQLPlus to execute SQL, PL/SQL and SQLPlus statements.
Usage 1: sqlplus -H | -V
-H Displays the SQL*Plus version and the
usage help.
-V Displays the SQL*Plus version.
Usage 2: sqlplus [ [] [{logon | /nolog}] [] ]
is: [-C ] [-F] [-L] [-M ""]
[-NOLOGINTIME]
[-R ] [-S]
-C <version> Sets the compatibility of affected commands to the
version specified by <version>. The version has
the form "x.y[.z]". For example, -C 10.2.0
-F This option improves performance in general. It changes
the default values settings.
See SQL*Plus User's Guide for the detailed settings.
-L Attempts to log on just once, instead of
prompting on error.
-M "<options>" Sets automatic HTML or CSV markup of output. The options
have the form:
{HTML html_options|CSV csv_options}
See SQL*Plus User's Guide for detailed HTML and CSV options.
-NOLOGINTIME Don't display Last Successful Login Time.
-R <level> Sets restricted mode to disable SQL*Plus commands
that interact with the file system. The level can
be 1, 2 or 3. The most restrictive is -R 3 which
disables all user commands interacting with the
file system.
-S Sets silent mode which suppresses the display of
the SQL*Plus banner, prompts, and echoing of
commands.
is: {[/][#<connect_identifier>] | / }
[AS {SYSDBA | SYSOPER | SYSASM | SYSBACKUP | SYSDG
| SYSKM | SYSRAC}] [EDITION=value]
Specifies the database account username, password and connect
identifier for the database connection. Without a connect
identifier, SQL*Plus connects to the default database.
The AS SYSDBA, AS SYSOPER, AS SYSASM, AS SYSBACKUP, AS SYSDG,
AS SYSKM and AS SYSRAC options are database administration privileges.
<connect_identifier> can be in the form of Net Service Name
or Easy Connect.
#[<net_service_name> | [[//]Host[:Port]/<service_name>] |
[[[protocol:]//]host1{,host12}[:port1]{,host2:port2}[/service_name]
[:server][/instance name][?[parameter name=value]
{&parameter name=value}]]]
<net_service_name> is a simple name for a service that resolves
to a connect descriptor.
Example: Connect to database using Net Service Name and the
database net service name is ORCL.
sqlplus username/mypassword#ORCL
Host specifies the host name or IP address of the database
server computer.
Port specifies the listening port on the database server.
<service name> specifies the service name of the database you
want to access.
Example: Connect to database using Easy Connect and the
Service name is ORCL.
sqlplus username/mypassword#Host/ORCL
The /NOLOG option starts SQL*Plus without connecting to a
database.
The EDITION specifies the value for Session Edition.
is: #|[.] [ ...]
Runs the specified SQL*Plus script from a web server (URL) or the
local file system (filename.ext) with specified parameters that
will be assigned to substitution variables in the script.
When SQLPlus starts, and after CONNECT commands, the site profile
(e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile
(e.g. login.sql in the working directory) are run. The files may
contain SQLPlus commands.
Refer to the SQL*Plus User's Guide and Reference for more information.
I would like a solution that only involves using a connection string. I don't want to be using tns_ora file
Also without any manual intervention. I don't want to separately enter the password after I put in 'username#connect-identifier'.
Please ignore security related issues of passing in the password visibly in the cmd prompt. That is fine with me.
Solution powershell script test-connect2.ps1:
$username = "demin"
$password = '"test#test"'
$connect_string ="10.241.33.71:1521/DEV"
$log_file = "log.txt"
$list_scripts = "connect $username/$password#$connect_string"
$list_scripts = $list_scripts + "
select 1,sysdate from dual;
#file1.sql
#file2.sql"
$list_scripts | sqlplus -s /nolog >>$log_file
Run script:
C:\instantclient_21_3>powershell .\test-connect2.ps1
output log.txt
1 SYSDATE
---------- ---------
1 27-MAY-22
2 SYSDATE
---------- ---------
2 27-MAY-22
3 SYSDATE
---------- ---------
3 27-MAY-22
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 27 06:34:41 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> alter user DEMIN identified by "test#test";
User altered.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
C:\>sqlplus demin/"test#test"#dev19
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 27 06:35:14 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:ORA-12154: TNS:could not resolve the connect identifier specified
Enter user-name:
C:\>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 27 06:35:23 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> show user
USER is "DEMIN"
SQL>
C:\app\product\18.0.0\dbhomeXE\bin>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 18.0.0.0.0 - Production on Fri May 27 10:28:18 2022
Version 18.4.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Last Successful login time: Fri May 27 2022 06:35:29 +03:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.12.0.0.0
SQL>
C:\instantclient_19_15>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 19.0.0.0.0 - Production on Fri May 27 11:23:35 2022
Version 19.15.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Fri May 27 2022 10:31:49 +03:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.12.0.0.0
SQL>
C:\instantclient_21_3>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 21.0.0.0.0 - Production on Fri May 27 11:18:08 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

SP2-0310: unable to open file "LOGIN.SQL" from Oracle DB 18c in Docker for Windows container

In Docker for Windows I installed an Oracle DB 18c XE Linux Docker container by the books:
Downloaded official sources (from https://github.com/oracle/docker-images)
Created an image from it
Created a container:
docker run --name $containerName -d -p 15210:1521 -e ORACLE_PWD=$dbPassword -v $dbVolume:/opt/oracle/oradata 'oracle/database:18.4.0-xe'
When I open SQL*Plus within the container, everything works fine:
> docker exec -it DevDB sqlplus sys/pwd#//localhost:1521/xe as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Fri May 21 19:47:10 2021
Version 18.4.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
In my Windows host I installed SQLPlus Instant Client. When I run SQL*Plus from there, I get a warning message telling me that "LOGIN.SQL" cannot be opened.
However, I seem to be able to run queries:
> sqlplus sys/pwd#//localhost:15210/xe as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Fri May 21 21:34:58 2021
Version 18.5.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SP2-0310: unable to open file "LOGIN.SQL"
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
What is causing this warning message? How can I get rid of it?
After some more testing I now found the answer to my issue:
Apparently, the reported error is a glitch in the 18.5.0.0 release of SQL*Plus.
I just updated SQL*Plus to 19.11.0.0, and the warning message is gone:
> sqlplus sys/pwd#//localhost:15210/xe as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri May 21 21:53:11 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>

Save imported oracle db dmp in docker image

I am using a docker image to start and run the Oracle db via docker-compose file. I have also created a dmp file of my application and been able to import it to the oracle server on docker using the docker exec -it command.
However every time I restart the docker container, the data is lost and I need to do the entire process of importing the dmp file again by doing a bash on the Oracle server in the docker container.
Is there any way I can save that data to the Oracle db server running on the docker container? I have tried docker commit however that did not work.
Do I need to use the volume bits?
You are correct in that volumes will be needed. Here's a full example working in my setup.
My volume mapping is : -v /Users/klrice/workspace/dockerdb/data:/opt/oracle/oradata
Then oracle directory : DIRECTORY docker_vol AS '/opt/oracle/oradata';
expdp cmd from host : docker exec -it db_193 expdp klrice/klrice#xe tables=t1 directory=docker_vol dumpfile=klrice.dmp logfile=klrice_exp.log
Resulting files are in the host mapped location: /Users/klrice/workspace/dockerdb/data
docker run --name db_193 --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
-p 1521:1521 \
-p 8000:8000 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=xe \
-e ORACLE_PWD=oracle \
-e ORACLE_CHARACTERSET=UTF8 \
-v /Users/klrice/workspace/dockerdb/data:/opt/oracle/oradata \
oracle/database:19.3.0-ee
kriss-MacBook-Pro:dockerdb klrice$ sql system/oracle#//localhost:1521/xe
SQLcl: Release 19.4 Production on Mon Nov 11 11:44:47 2019
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Mon Nov 11 2019 11:44:48 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> CREATE OR REPLACE DIRECTORY docker_vol AS '/opt/oracle/oradata';
Directory DOCKER_VOL created.
SQL> GRANT READ, WRITE ON DIRECTORY docker_vol TO klrice;
Grant succeeded.
SQL>
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
kriss-MacBook-Pro:dockerdb klrice$ docker exec -it db_193 expdp klrice/klrice#xe tables=t1 directory=docker_vol dumpfile=klrice.dmp logfile=klrice_exp.log
Export: Release 19.0.0.0.0 - Production on Mon Nov 11 16:45:01 2019
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "KLRICE"."SYS_EXPORT_TABLE_01": klrice/********#xe tables=t1 directory=docker_vol dumpfile=klrice.dmp logfile=klrice_exp.log
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "KLRICE"."T1" 6.680 MB 1000000 rows
Master table "KLRICE"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for KLRICE.SYS_EXPORT_TABLE_01 is:
/opt/oracle/oradata/klrice.dmp
Job "KLRICE"."SYS_EXPORT_TABLE_01" successfully completed at Mon Nov 11 16:45:15 2019 elapsed 0 00:00:13
kriss-MacBook-Pro:dockerdb klrice$ ls /Users/klrice/workspace/dockerdb/data/klrice*
/Users/klrice/workspace/dockerdb/data/klrice.dmp /Users/klrice/workspace/dockerdb/data/klrice_exp.log

What to do whenever I opens my browser it shows "ORACLE DATABASE 10g EXPRESS EDITION LICENSE AGREEMENT"?

None of my browser are working whenever I query in browser I get the message "ORACLE DATABASE 10g EXPRESS EDITION LICENSE AGREEMENT". What to do?
I too faced same issue and fixed the issue by following these steps. Please have a try.
From Start | Run open a command window. Assuming your environmental variables are set correctly start with the following:
C:\>sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Aug 26 10:40:44 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> connect
Enter user-name: system
Enter password: <enter password if will not be visible>
Connected.
SQL> Exec DBMS_XDB.SETHTTPPORT(3010); [Assuming you want to have HTTP going to this port]
PL/SQL procedure successfully completed.
SQL>quit
Now restart the PC and check.

Resources