Oracle Database Development With Docker
Oracle Database Development With Docker
Witold Swierzy
Data Management Expert
Table of contents
Introduction
Introduction
Almost everyone has heard the opinion, that Oracle Database is the excellent example of an old, traditional, pure-relational,
old-fashioned etc, etc, etc... monolithic databaase, which, additionally to that, is also very expensive. Yup. We've heard it too.
But the fact is that it is completely false. In this article we will prove, that it is possible and easy to build a system, which
meets all the modern development approaches, can be provisioned in a minute, has everything needed to start developing
an application, which uses all possible data models and - is completely for free! To do this we will use the following
components
Below picture is also very well known, I think, to most of Oracle Database users and administrators: it describes one of
obvious use cases of Oracle Database multitenant option: support for containerized applications
But in this article we will describe a dicerent scenario: instead of providing support for external containers, we will build a
container which will provide all the typical Oracle Converged Database services: SODA, PGQL, REST, MongoDB API and
APEX. If you want to learn more about Oracle's converged database features, you can get an overview in the posting Oracle
Database Development #blockchain #graph #JSON #lowcode #spatial #SQL #textsearch #XML.
All the below commands need to be executed as root on our host machine:
Container Con5guration
As we have Docker installed and conigured, so we can start to work on the second stage of our project - development of an
Oracle Database Express Edition Docker image. We will start from creating a "golden image" - Docker Oracle Linux 8
container where everything will happen... (now we don't need to work as root - instead of this we will use the account
created/modiied in the last step of Docker installation stage)
# As we need to install a couple of packages, like Oracle preinstall check, Oracle RDBMS, ords,...
# ...instead of uploading everything into the container, it is better to create it with a folder shared with the host...
# ...we also need to remember about port mapping...
# ...and providing some environment variables into the container, which we will use during software configuration
mkdir $HOME/orainstall
docker create -it --name oracle21xe -p 1521:1521 -p 5500:5500 -p 8080:8080 -p 8443:8443 -p 27017:27017 \
-e DBA_PWD=ConvergedDB_1234 -e USR_PWD=ConvergedDB_1234 \
-e DOCKER_HOST=NOHOSTNAME \
-v $HOME/orainstall:/orainstall oraclelinux:8
where
DBA_PWD is the environment variable, which will provide to the container DBA password - in the above example we have
set it to "ConvergedDB_1234", and - of course - it can be customized later
USR_PWD is the environment variable, which will provide to the container end user password - in the above example also
set to "ConvergedDB_1234"
DOCKER_HOST is the environment variable, which is required only if you want to activate SSL for ORDS. In that case it
needs to be set to the real "[Link]" or IP address of the host machine. In the above example, as we'll see later,
"NOHOSTNAME" value causes, that ORDS will work only in non-SSL mode.
To complete next steps we need to download and store in $HOME/orainstall the following software
Now let's install few standard linux packages, which will be used in our coniguration
As you see, for the purpose of this post we are using OpenJDK instead of OracleJDK... In case of any license-related
questions please refer to OracleJDK Licensing FAQs page or contact your sales representative.
Now we can install the software, which we have downloaded into orainstall folder: Oracle Database 21c Preinstall Check,
Oracle Database 21c XE, ORDS and Apex. The procedure is exactly the same as in case of installing it on a physical machine,
so I will not describe in this article how to do this. The only dicerence is that in case of installing Oracle Database software in
a Docker container we need to set ORACLE_DOCKER_INSTALL environment variable to true:
The next step is technically optional. We can (but it is not a technical requirement) add oracle user to sudoers ile to allow it
to make sudo to root. But if we want to make our "Golden Oracle Database Image" customizable - we should do it - it would
be possible to make sudo to root and extend functionality of this installation.
After that let's make our life a liqle bit easier, by adding some environment variables to oracle's .bashrc ile and seqing a
password for this account
Now we can "install" ORDS and APEX - I mean - simply unzip iles into appropriate directories...
# ...let's become "oracle" user inside of the container we're working on...
su - oracle
# ...being already "oracle" - create a directory for ORDS configuration...
mkdir $HOME/ordsconfig
# ...and another directory, where we'll place all the scripts required to automate the startup and configuration process...
mkdir /opt/oracle/scripts
# ...and "install" ords and apex - which means simply unzipping appropriate files into appropriate directories.
unzip /orainstall/[Link] -d /opt/oracle/ords
unzip /orainstall/apex_22.[Link] -d /opt/oracle/product/21c/dbhomeXE
The next step is to conigure APEX and ORDS - exactly in the same way as in case of a traditional installation on a physical
machine. As these processes are well documented in many manuals, blog posts and even some Youtube videos, I will not
describe them here, just want to add the note, that even in case when we plan to run an SSL-based coniguration, at the
stage of initial coniguration of ORDS we'll conigure only h7p mode and port 8080... Why? Of course, if we have an SSL
certiicate, then we can conigure ORDS to use hqps from its irst run, but we assume in this post, that our container is not
being built for a production purposes, (which usually means, that we have company certiicates, public domains, etc...) but
rather for a demonstration. In that case ORDS started with --secure parameter will generate its own, self-signed certiicate,
which is good enough for doing some demos, even if it causes, that a web browser generates a warning...
After coniguring ORDS we may want to (as it is not being done in ords installation automatically)
Create an additional database user, which will play the role of a "developer" and grant to this account privileges allowing
for development a database application.
Conigure a Database Actions user. It is described, for example here.
The last step is speciic to our confguration and - the most important - we need to automate the initial coniguration and
startup of OracleNet, database and ords... Of course - there are many ways of how to do this, but there's always need to
remember about one fundamental dicerence between a docker-based installation and installation on a physical or even
virtual, but "traditionally virtualized" machine: Docker Oracle Linux 8 image doesn't use systemd, since then
typical oratab-based methods are in such cases not applicable. In this article we'll use an ancient and (almost, fortunately
not quite) forgoqen art of shell scripting ;).
Below diagram presents scripts which we want to develop. All of them will be stored in /opt/oracle/scripts directory and
owned by "oracle" user:
[Link] (main script, which will be used in EntryPoint attribute of the Docker image we're working on)
|
|---- [Link] (executed only once, during container first start, it configures [Link] and [Link] files
|
|---- [Link] (executed every time when container starts. It starts listener and the database)
| |
| |
| ---- [Link] (starts the database)
|
|---- [Link] (executed only once, during container first start, it configures passwords for database users
| and oracle OS user
| |
| |
| ---- [Link] (called by [Link], it changes passwords directly in the database)
|
|
---- [Link] (executed every time container starts - it starts ords)
So - at the beginning let's automatize the OracleNet iles coniguration. We need to do this, as their content ([Link] and
[Link]) depends on a hostname of the CONTAINER. And this hostname may be setup automatically during a
container creation...
The next two scripts will change database passwords to $DBA_PWD and $USR_PWD: [Link] and
[Link]
Two other scripts are responsible for starting the database up:
if [ "$DOCKER_HOST" = "NOHOSTNAME" ];
then
# if we have not changed DOCKER_HOST value to a non-default, then it means that we want to use only non-SSL configuration
nohup ords serve >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1 &
else
# we have provided a non-default value for DOCKER_HOST, then it means, that we want to use SSL-based configuration
# in that case ords will generate its own self-signed certificate during the first startup
nohup ords serve --secure --port 8443 >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1 &
fi
--- end of [Link] ---
Now it's time to inalize our small project. The main script - [Link]
Copy code snippet
#!/bin/bash
# as we will use this script as the container entrypoint, it will not execute $HOME/.bashrc...
# ...so we need to setup the environment.
export ORACLE_NET_HOME=/opt/oracle/homes/OraDBHome21cXE/network/admin
export ORACLE_CFG_SCRIPTS=/opt/oracle/scripts
export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE
export ORACLE_SID=XE
export ORDS_HOME=/opt/oracle/ords
export ORDS_CONFIG=$HOME/ordsconfig
export PATH=$ORACLE_CFG_SCRIPTS:$ORACLE_HOME/bin:$ORDS_HOME/bin:$PATH
if [ ! -f ${ORACLE_CFG_SCRIPTS}/system_already_configured ];
then
printf "Starting OracleNet configuration\n" >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
${ORACLE_CFG_SCRIPTS}/[Link] >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
printf "OracleNet configuration completed\n" >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
if [ "$DOCKER_HOST" != "NOHOSTNAME" ];
then
printf "ORDS SSL reconfiguration.\n"
# we need to remove an old self-signed certificate if it exists. Otherwise ords will not generate a new one
rm -f ${ORDS_CONFIG}//global/standalone/self-signed.*
# we need to configure [Link] property in order to make SSL-based configuration working
ords config set [Link] ${DOCKER_HOST} >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
printf "ORDS SSL reconfiguration completed.\n"
fi
fi
# if the database instance is not up, there's need to start it up with apex
if [ `ps -ef|grep lgwr|wc -l` -lt 2 ];
then
${ORACLE_CFG_SCRIPTS}/[Link] >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
${ORACLE_CFG_SCRIPTS}/[Link] >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
fi
# if we start the container for the first time, there is need to change default passwords
if [ ! -f ${ORACLE_CFG_SCRIPTS}/system_already_configured ];
then
printf "Starting password configuration\n" >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
${ORACLE_CFG_SCRIPTS}/[Link] ${DBA_PWD} ${USR_PWD} >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
printf "Password configuration completed\n" >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
touch ${ORACLE_CFG_SCRIPTS}/system_already_configured >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
printf "New system configuration completed\n" >> ${ORACLE_CFG_SCRIPTS}/[Link] 2>&1
fi
tail -f /opt/oracle/scripts/[Link]
Of course, we have to remember about adding execution privilege to all *.sh scripts we have created:
Now we can create a test container to check how our setup works
Application Express
in case, when SSL is conigured: hqps://<docker_host_machine>:8443/ords
Database Actions
In case, when SSL is conigured: hqps://<docker_host_machine>:8443/ords/sql-developer
Of course, as oracle user is in /etc/sudoers ile, we can use root account of the container to install additional packages or, in
general, perform further customizations. In general - we have full control over the image we've created, which, in case of a
test installation is rather an advantage (however - in case, when we want to use such image for a produciton purpose, such
coniguration may drive to some security threads).
Summary
To summarize all the steps we have completed:
We have created a Docker image, providing all the services, which are required in a modern development environment,
using Oracle Database as its foundation.
This image can be used to provision and start a new environment in a minute.
Such Oracle Database Golden Image can be easily used in dicerent CI/CD scenarios, it meets requirements of any modern
development environment or DevOps/SysOps approaches. Also Oracle 21c Express Edition has many features coming
directly from Enterprise Edition, like, for example, Partitioning or In-Memory options. It also supports multi- and cross-
model approach of Converged Database. Of course it has also some limitations, but it is an obvious result of its price - its
for free :). So - please, don't believe in rumours and fake opinions and instead of this...
Note
This Article has been updated to use the newest version of the Oracle Database software:
Oracle Databas 23c Free Developer Edition. Updated version can be found here
Witold Swierzy
Data Management Expert
Witold studied mathematics. He works at Oracle in Warsaw as a EMEA Data Management Expert.
His main responsibilities cover providing to our customers knowledge related to the newest options
Show more
and features of Oracle Database. He is also lecturer, working at Warsaw School of Economics, where
he gives lectures related to modern IT technologies.
About Analyst Reports What is Customer Service? Try Oracle Cloud Free Tier US Sales 1.800.633.0738
Careers Best CRM What is ERP? Oracle Sustainability How can we help?
Developers Cloud Economics What is Marketing Automation? Oracle COVID-19 Response Subscribe to Oracle Content
Investors Corporate Responsibility What is Procurement? Oracle and SailGP Try Oracle Cloud Free Tier
Partners Diversity and Inclusion What is Talent Management? Oracle and Premier League Events
Startups Security Practices What is VM? Oracle and Red Bull Racing News
Honda
© 2024 Oracle Privacy / Do Not Sell My Info Cookie Preferences Ad Choices Careers