#Docker: Production #Jboss client image that checks if the #Oracle container is initialized with data

By | April 7, 2017

Everybody that works with big vendor databases like Oracle or DB2 knows that when you have a lot of data and the database is initializing or recovering after a disaster there are dead times when the database isin a state of limbo. It is started but still not in usable state.
Usually the enterprise applications should be decoupled from the DB layer, such that they are able to cope with the DB not being available for short moments and be able to continue to work after the DB is available again.
The above may not be true in the initial initialization stage of the main applications when initialization steps need to extract information from the database to be able to start. In this case sometimes the simple dependency checks done by docker-compose are not enough.

We may have the following minimal setup docker-compose.yml

Where “application” is an Jboss EAP based web application that is using an oracle database 12c container for data storage.

The oracle image is define as the following:

Note that we are creating users, tables, procedures and import data using the init.sql script.

The “links” section will make sure that the oracle container is started before the application container but this is not enough. My application needs to wait for Oracle to finish init.sql and that takes time when there are a lot of things to be created and imported.

This imposes the need to define a more complex way for the application container to wait for the oracle container to finish.

My solution was to use the nice Oracle Instant Client and a start-up script with a check to create a Jboss based image that waits for a complex initialization of the oracle database container.

STEP 1: Define the application Dockefile

I start from jboss/base-jdk:8 image.

STEP 2: Add the section to install jboss-EAP 7.0.0

The following section will install kits/jboss-eap-7.0.0.zip downloaded from Red-Hat official repository (paid support account needed).

STEP 3: Install the oracle instant client

Download the Oracle Instant client binary rpms and the dependency library libaio-0.3.109-13.el7.x86_64.rpm.
Then add the following section:

Note 1: We have to switch context to the root user to be able to install rpms into the image.

Note 2: We have to load the new installed oracle libraries into the kernel.
The content of the scripts/oracle.conf is:

STEP 4: Copy the start-up script and set it as the entry point
Finally switch back to the jboss user context and copy and set the start-up script

STEP 5: Final Dockerfile

STEP 6: Start-up script

The startApplication.sh will use the test.sql test to check if the database initialization is done.

Note that creation of the PROC12 procedure is the last action done in the init.sql, so we are certain that after it is created the database is initialized.

The script looks like the following:

Note 1: Bash Procedure wait_for_oracle_server will wait in a loop and test using the sqlplus64 client until procedure PROC12 is created.

Note 2: From some weird reason I have to delete “/opt/jboss/jboss-eap-7.0/standalone/configuration/standalone_xml_history/current”. Jboss tries to rename the current history to another directory and fails. It looks like a known issue with Jboss in Docker

The end result is a Jboss EAP 7.0.0 + Oracle Instant Client image that is able to wait before starting for the Oracle database container to end the initialization.


One thought on “#Docker: Production #Jboss client image that checks if the #Oracle container is initialized with data

  1. Pingback: #Docker: Custom #JBoss EAP docker image with CLI applied patches and CLI configurations – blog.voina.org

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.