why
Using an Oracle Docker container is much easier than a traditional stand-alone installation.
Meanwhile, starting with Oracle Database 21c, the only supported architecture is the multitenant container database, which significantly enhances data accessibility and portability. This new architecture introduces 2 important concepts that are crucial for efficient database management: multitenant container database (CDB) and pluggable databases (PDBs).
For more information, please refer to https://developer.oracle.com/en/learn/technical-articles/what-is-a-container-database.
what
In this article, I will introduce how to setup an Oracle server by creating and running the Oracle 21c docker container.
I will just focus on providing all the necessary steps, rather than introduce all the concepts and commands.
In my case, I need to prepare an Oracle Server with the following information:
Oracle
- Host Name: test.mycloud.com
- Port: 1521
- Oracle Network Service Name: dds
- Database Schema Name for Insurance DDS: dds
- User ID: ddsuser
- Password: Go4thsas
Host (test.mycloud.com)
- OS Version
- Red Hat Enterprise Linux release 8.6 (Ootpa)
- Docker Version:
- podman version 4.9.4-dev
- Note: Podman has replaced Docker on redhat8.
- Note: most users like simply alias Docker to Podman (“alias docker=podman” )
- In my host, I need to use root user to run all the docker commands.
How
- Docker Hub – Authentication
- Go to the Oracle Container Registry page: https://container-registry.oracle.com
- Click “Sign In” on the top right corner of the page, and log on with your personal Oracle account.
- Enter the “Database” repositories.
- Click “enterprise” repository.
- On the right panel, choose the language to accept the Oracle Standard Terms and Restrictions.
- Click your account name on the top right. Choose “Auth Token” from the menu.
- On the Auth Tokens page, click Generate Token.
- If it displays that the token is already existed, then Delete Secret Key at first and generate it again.
- Copy the token and save it somewhere.
- Pull the Docker Image
- Once we have the credentials, execute the following command to login on the linux host. Use the token saved at step 1.h as the password.
docker login container-registry.oracle.com - Pull the docker image
docker pull container-registry.oracle.com/database/enterprise:latest
- Once we have the credentials, execute the following command to login on the linux host. Use the token saved at step 1.h as the password.
- Create and run the container
docker run -d –name ddscdb -p 1521:1521 -p 5500:5500 -e ORACLE_SID=ddscdb -e ORACLE_PWD=Go4thsas -e ORACLE_PDB=dds -v /install/oradata:/opt/oracle/oradata container-registry.oracle.com/database/enterprise:21.3.0.0 - Configure inside the container
- Enter the container
docker exec -it ddscdb sqlplus sys/Go4thsas@ddscdb as sysdba - Swith to the pdb container
SQL>alter session set container=dds; - Create user and assign privileges
SQL>create user ddsuser identified by Go4thsas account unlock; SQL>grant all privileges to ddsuser;
SQL>exit
- Change to use root to enter it to install edit tool
docker exec -it -u root ddscdb bash bash-4.2# yum install –y vim
bash-4.2# exit
- Change to use default user to add tnsnames.ora for the oracle container
docker exec -it ddscdb bash bash-4.2$ cd $ORACLE_HOME/network/admin
bash-4.2$ vim tnsnames.ora
DDSCDB=localhost:1521/DDSCDB
DDS=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DDS)))
- Restart listener
bash-4.2$ lsnrctl stop bash-4.2$ lsnrctl start
- Check the status of the listener
bash-4.2$ lsnrctl status LSNRCTL for Linux: Version 21.0.0.0.0 – Production on 05-JUN-2024 10:03:57
Copyright (c) 1991, 2021, Oracle. All rights reserved.
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 05-JUN-2024 06:46:28
Uptime 0 days 3 hr. 17 min. 29 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/f77014ebf49c/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=f77014ebf49c)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/DDSCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary…
Service “19f79b261d640cf3e0630600580a3d5a” has 1 instance(s).
Instance “DDSCDB”, status READY, has 1 handler(s) for this service…
Service “DDSCDB” has 1 instance(s).
Instance “DDSCDB”, status READY, has 1 handler(s) for this service…
Service “DDSCDBXDB” has 1 instance(s).
Instance “DDSCDB”, status READY, has 1 handler(s) for this service…
Service “dds” has 1 instance(s).
Instance “DDSCDB”, status READY, has 1 handler(s) for this service…
The command completed successfully
- Verify the connection
docker exec -it ddscdb sqlplus ddsuser/Go4thsas@dds
SQL*Plus: Release 21.0.0.0.0 – Production on Wed Jun 5 10:06:55 2024
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Wed Jun 05 2024 06:47:11 +00:00
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 – Production
Version 21.3.0.0.0
SQL>
- Enter the container
- Configure outside the container
- Install Oracle Instant Client Using RPMs
- Download rpms at Instant Client for Linux x86-64 (64-bit)
- Install them
dnf install oracle-instantclient-basic-21.14.0.0.0-1.el8.x86_64.rpm dnf install oracle-instantclient-sqlplus-21.14.0.0.0-1.el8.x86_64.rpm
- Add the environment variables for the SAS install user
cd /install/users/cfgsas1 vim .bashrc
export ORACLE_HOME=/usr/lib/oracle/21/client64/lib
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
export PATH=/usr/lib/oracle/21/client64/bin:$PATH
source .bashrc
- Add the tnsnames.ora
cd $ORACLE_HOME/network/admin vim tnsnames.ora
DDSCDB=localhost:1521/DDSCDB
DDS=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DDS)))
- Install Oracle Instant Client Using RPMs
- Test the connection outside the container
sqlplus ddsuser/Go4thsas@dds
SQL*Plus: Release 21.0.0.0.0 – Production on Wed Jun 5 10:06:55 2024
Version 21.14.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Wed Jun 05 2024 06:47:11 +00:00
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 – Production
Version 21.3.0.0.0
SQL>
Done!
Reference
[1] Oracle Help Center: Oracle CDBs and PDBs
[2] Oracle Help Center: Oracle 21c Multitenant Administration Guide
[3] Oracle Help Center: How to Install Oracle Database 21c on Docker
[4] Oracle Container Registry: Oracle Database Server Release 21c (21.3.0.0) Docker Image Documentation
[5] Medium Post: Run Oracle Database 21c in Docker
[6] Oracle Help Center: Oracle Cloud Infrastructure Documentation – Getting an Auth Token
[7] Oracle Help Center: Installing Oracle Instant Client Using RPMs