cloud, Database, Docker, Oracle

Using the Oracle Instant Client with Docker and Oracle DB12c

This weekend, in my desire to learn more about Docker, I decided to implement a multi-container solution. In this PoC, I plan to deploy a container with the Oracle Database 12.1 and a second container with the Oracle Instant Client 12.2. The goal will be to connect to the Database container from the Instant Client deployed in the second container.  So let’s get started.

Environment:
macOS Sierra v10.12.5
MacBook Pro (Retina, 15-inch, Mid 2014)
Processor 2.2 GHz Intel Core i7
Memory 16 GB
Docker Community Edition v17.06

Prerequisites:
Docker Community Edition – Installed
Account on Docker Store – https://store.docker.com

The first thing we need to do is pull down the database and the instant client images. Fortunately for us, Oracle has name this easy as they have made both of these images available in the Docker Store. You can read more about Oracle and Docker here.

In the Docker Store you can either perform a search on Oracle in the search box, or click this link here to access the Oracle images in store.

You may need to provide some information for Oracle Development Licensing Agreement(s) before you can see the list of images. Once completed, you will need to select both the Instant Client image and the Database image sections.

Now that you have “subscribed” to the images, open and terminal window and execute the following command:

docker pull store/oracle/database-instantclient:12.2.0.1
Example Screenshot:

 

docker pull store/oracle/database-enterprise:12.1.0.2
You will see a similar screen as above if you haven’t already pulled the image. Note this is a Oracle DB12.1 image and is around 5GB and will take some time to download.

Once the download is complete, execute a docker images at the command prompt and you should see the two images you pulled.

 

Now we need to do some set up for the database container. Back in the Docker Store, you can click on the Set Instructions button to get the additional steps, or you can follow along here.

 

Create a file using the sample Environment file. I’ve made a couple of changes back to the default values so feel free to copy and paste this into a file: docker_db_setup.txt

####################################################################
## Copyright(c) Oracle Corporation 1998,2016. All rights reserved.##
##                                                                ##
##                   Docker OL7 db12c dat file                    ##
##                                                                ##
####################################################################

##------------------------------------------------------------------
## Specify the basic DB parameters
##------------------------------------------------------------------

## db sid (name)
## default : ORCL
## cannot be longer than 8 characters

DB_SID=ORCL

## db passwd
## default : Oracle

DB_PASSWD=oracle

## db domain
## default : localdomain

DB_DOMAIN=localdomain

## db bundle
## default : basic
## valid : basic / high / extreme 
## (high and extreme are only available for enterprise edition)

DB_BUNDLE=basic

## end

 

The following command must be executed in the same directory as the Environment file:

docker run -d –net bridge –env-file ./docker_db_setup.txt -p 1521:1521 -p 5500:5500 -it –name DB121Container –shm-size=”8g” store/oracle/database-enterprise:12.1.0.2

 

Connect to the DB Container and execute the setup script:
Danny: > docker exec -it dockerDB121 /bin/bash
[root@70c9d35d1889 /]# /bin/bash /home/oracle/setup/dockerInit.sh

This terminal will remain in a loop, so just minimizes this and user another terminal for future work. At this point we can open a new terminal session and connect to the database using SQLPLUS included with the DB.

Danny: > docker exec -it DB121Container /bin/bash
[root@08aef464a2be /]# su – oracle
[oracle@08aef464a2be ~]$ lsnrctl status

[oracle@08aef464a2be ~]$ sqlplus / as sysdba

Now that we have successfully connected with SQLPLUS installed with the database, let’s deploy our second container with Oracle Instance Client and connect from there. Note that we have connected using SQL*Plus Release 12.1.0.2.0

Before doing so, we need to find the IP Address of the database container. We will do this with the docker inspect <container> command.

First we need to find the Container ID:

Danny: > docker container ls

In this case, that ID is: 08aef464a2be. Fortunately, we don’t have to remember this entire number, but that’s a different discussion.

Next we can use the docker inspect command. Since this will provide a JSON doc with a ton of info about the container, I’ll grep for the IPAddress:

Danny: > docker inspect 08a | grep -i IPAddress Notice that I only needed the the first few characters of the container ID. This is because the ID that Docker assigns is unique enough that I need on a few characters to help the command identify the container. Of course programmatically, you can grab the entire ID and be just fine.

Here we can see that the IP Address is: 172.17.0.2. Docker internally creates is own network which is what this address is not part of your host ip network.

Armed with this information, we can now create our second container with the Oracle Instant Client and connect to the Oracle Database we just deployed using the IP Address we found in the previous step and the database information we configured in the Environment file and confirmed with the lsnrctl status command.

Danny: > docker run -ti –name instclient –rm store/oracle/database-instantclient:12.2.0.1 sqlplus system/oracle@//172.17.0.2:1521/orcl.localdomain

… and there you have it.

Oracle Database 12.1 deployed to a container and we have connected to it via an Oracle Instant Client deployed to a second container, and we can see here that the connection is via SQL*Plus Release 12.2.0.1.0 which matches the version of the Instant Client we pulled from the Docker Store.

Why is this concept important?

  • Using containers lets you develop applications as microservices.
  • Containers support application isolation so you can run multiple versions simultaneously.
  • If one part of the application fails, the other components can continue to operate. With proper orchestration strategies in place a failed application container can be redeployed with minimal service interruption.
  • Server/Hardware ubiquity. Perfect for deployment to the cloud where infrastructure may be a black box.

Where do we go from here?

With the use of the Oracle Instant Client, we can now install something like node and the node driver for the oracle database without the concern of bringing down the database. (Hint on a later post).

Enjoy

Related Posts Plugin for WordPress, Blogger...

1 Comment

Leave a Reply

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