Site icon Ron Ekins' – Oracle Technology, DevOps and Kubernetes Blog

Oracle 19c on Docker and Kubernetes Part 2- Running Oracle on Docker

Oracle 19c Docker Image

In Part 1 of this Blog series I showed how you can obtain the official Oracle 19.3 Docker image from the Oracle Container Registry, if you missed the you can read more about getting the Oracle 19c image here.

You can still use the Oracle provided Docker build scripts to roll your own Oracle Docker images, and I have a Blog showing how can use the Oracle GitHub scripts to deliver different database versions.

For reference I have also an old blog documenting how you can get the Official Oracle 12c Docker image from the Docker Hub and you can re-familiarise yourself it here. Note it looks like Oracle is no longer maintaining the Docker Hub so I suggest you use the Oracle Container Registry going forward.

Getting start with Docker

Before we begin lets check our version of Docker with docker –version, you can also try docker version for a more verbose output.

$ docker --version
Docker version 19.03.13, build 4484c46d9d

And lets list our Docker images with docker images or if you prefer docker image ls

$ docker images
REPOSITORY                                        TAG      IMAGE ID     CREATED      SIZE
container-registry.oracle.com/database/enterprise latest   2e375ab66980 2 months ago 6.66GB
container-registry.oracle.com/database/enterprise 19.3.0.0 2e375ab66980 2 months ago 6.66GB

Before we start let’s inspect our Oracle image to confirm the Oracle version.

$ docker image inspect container-registry.oracle.com/database/enterprise | grep INSTALL_FILE_1
"INSTALL_FILE_1=LINUX.X64_193000_db_home.zip"

Running the Docker Container

The Oracle 19.3 Docker image supports a number of optional parameters, if not specified they will use defaults, the minimum docker run command to start your container detached -d is:

$ docker run -d --name <container name> container-registry.oracle.com/database/enterprise:19.3.0.0

For this post I will pass the following settings using environmental variables.

# default value ORCLCDB
ORACLE_SID=PSTGCDB 
# default value ORCLPDB1
ORACLE_PDB=PSTGPDB1 
# default value random
ORACLE_PWD=Docker#2020 
# enterprise or standard default enterprise 
ORACLE_EDITION=enterprise
# default value AL32UTF8 
ORACLE_CHARACTERSET=AL32UTF8
#
ORADATA=/Users/rekins/19c/oradata
ORASTARTUP=/Users/rekins/19c/startup
ORASETUP=/Users/rekins/19c/setup
#
CON_NAME=my19c
LISTENER=1521
OEM=5500
docker run -d --name ${CON_NAME} \
-p ${LISTENER}:1521 -p ${OEM}:5500 \
-e ORACLE_SID=${ORACLE_SID} \
-e ORACLE_PDB=${ORACLE_PDB} \
-e ORACLE_PWD=$(ORACLE_PWD} \
-e ORACLE_EDITION=${ORACLE_EDITION} \
-v ${ORADATA}:/opt/oracle/oradata \
-v ${ORASTARTUP}:/opt/oracle/scripts/startup \
-v ${ORASETUP}:/opt/oracle/scripts/setup ${IMAGE}

We can use the Docker Dashboard to show our images are available and in use.

Docker Dashboard – Images

And the name(s) of running Containers

Docker Dashboard – Containers

We can watch the progress of the Container startup with docker logs <container name> –follow

In the output below you can see the Oracle 19c Docker container is using the environmental variables passed to the container.

$ docker logs my19c --follow
[2020:10:07 16:44:02]: Acquiring lock on /opt/oracle/oradata/.PSTGCDB.create_lck
[2020:10:07 16:44:02]: Lock acquired on /opt/oracle/oradata/.PSTGCDB.create_lck
[2020:10:07 16:44:02]: Holding on to the lock using /tmp/.PSTGCDB.create_lck
ORACLE EDITION: ENTERPRISE
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: Docker#2020

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 07-OCT-2020 16:44:02

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/433cdb7a0052/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 19.0.0.0.0 - Production
Start Date                07-OCT-2020 16:44:02
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/433cdb7a0052/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
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/PSTGCDB.
Database Information:
Global Database Name:PSTGCDB
System Identifier(SID):PSTGCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/PSTGCDB/PSTGCDB.log" for further details.

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Oct 7 17:04:44 2020
Version 19.3.0.0.0

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

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> 
System altered.

SQL> 
System altered.

SQL> 
Pluggable database altered.

SQL> 
PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
PSTGPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2020-10-07T17:04:44.742310+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/PSTGCDB/control01.ctl' SCOPE=SPFILE;
2020-10-07T17:04:44.749760+00:00
ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
   ALTER PLUGGABLE DATABASE PSTGPDB1 SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE PSTGPDB1 SAVE STATE
2020-10-07T17:04:45.845680+00:00

XDB initialized.

We can use docker inspect <container name> or the Docker Dashboard to check our environmental variables.

Docker Dashboard – Container Inspect

Connecting from outside of the container

We can connect to out container remotely using SQL*Plus, first get the your container port.

$ docker port my19c
1521/tcp -> 0.0.0.0:1521
5500/tcp -> 0.0.0.0:5500
$ sqlplus sys/<your_password>@//localhost:1521/<your_sid> as sysdba
$ sqlplus sys/Docker#2020@//localhost:1521/PSTGCDB as sysdba @database_details

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Oct 7 18:18:29 2020
Version 19.3.0.0.0

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

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

Current Time   : 07/10/20 17:18:29

Database Details
===============================================
Hostname       : 433cdb7a0052
Database Name  : PSTGCDB
Date Created   : 07/10/20 16:46:08
Date Started   : 07/10/20 17:04:12
Resetlogs Date : 07/10/20 16:46:11
DB Status      : OPEN
Space Allocated: 1.69 GB
Space Used     : 1.66 GB

We can also connect to our pluggable database using:

$ sqlplus pdbadmin/<your_password>@//localhost:1521/<your_pdbname>
$ sqlplus pdbadmin/Docker#2020@//localhost:1521/PSTGPDB1

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Oct 7 18:24:51 2020
Version 19.3.0.0.0

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

Last Successful login time: Wed Oct 07 2020 18:23:36 +01:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show con_name;

CON_NAME
------------------------------
PSTGPDB1
SQL> 

In Part 3, I will share how you can take our Oracle 19.3 Docker image and use it with a Minikube Kubernetes environment.

[twitter-follow screen_name=’RonEkins’ show_count=’yes’]

Exit mobile version