X

Step Up to Modern Cloud Development

Test and Deploy WebLogic and Oracle Database Applications on Docker

Monica Riccelli
Product Manager

Tight integration between Oracle WebLogic Server and Oracle Database provide a strong infrastructure to develop, and test application with improved availability, better resource sharing, ease of configuration and automated management facilities. When both of these products are running in Docker containers we can take advantage of Docker’s benefits of container isolation, container portability, packaging, instant replay and reset to provide the ability to automate the development and testing of these applications.

On GitHub we provide the necessary Dockerfiles and scripts to run both an Oracle Database EE 12c and WebLogic Server 12c containers. We also provide samples that you can expand to deploy your own applications in this environment. I will describe how to containerize WebLogic Server which connects to a containerized Oracle DB, deploy a MedRec application which has its data persisted in the database. 

What you will need

Environment

For this article, I've used the following environment:

  • Oracle Linux 7.2 UEK 4 (and the Oracle Linux image for Docker)
  • Docker 1.10.3 
  • Oracle Database 12.2.0.1 Enterprise Edition
  • Oracle WebLogic Server 12.2.1.2 (quick installer and supplemental quick installer)
  • Oracle Java JDK 8u121
  • Oracle SQLcl 4.2

Run Oracle Database container

We will run the container using the docker run command. One important parameter is the -p for the mapping of ports inside the container to the outside world. This is of course required so that we can also connect to the database outside the Docker container. Another useful parameter is the --name parameter which allows us to give our newly created Docker container a name defined by us. By doing so we can refer to the container via that name rather than the automatically generated ID/name:

$ docker run --ipc=host  \
  --name my_db \
  -p 1521:1521 \
  -p 5500:5500 \
  -e ORACLE_SID=ORCLCDB  \
  -e ORACLE_PDB=ORCLPDB1 \
  store/oracle/database-enterprise:12.1.0.2

On the very first startup of the container a new database is being created. Subsequent startups of the same container just start up the database again. For convenience purposes the container startup script also runs a tail -f on the Oracle Database alert.log file. This is done for convenience purposes only so that any potential issues can be easily spotted. Once you see the line DATABASE IS READY TO USE! in the output you can connect to the database. Note that the startup script also generated a password for the database admin accounts. You can find the password next to the line ORACLE AUTO GENERATED PASSWORD FOR SYS, SYSTEM AND PDBAMIN in the output. You can either use that password going forward or you can reset it to a password of your choice. The container provides a script called setPassword.sh for resetting the password. In a new shell just execute following command against the running container:

$ docker exec my_db ./setPassword.sh LetsDocker

We need to create the tables and populate them with data that the application will need.  Run sqlplus to create and populate tables for WebLogic medrec application to run the ddl. Download and install sqlcl, a new command-line tool for connecting to the Oracle Database.

~/sqlcl/sqlcl/bin $ ./sql system/LetsDocker@xxx.xxx.x.xxx:1521/ORCLCDB

SQL>@~/docker-images/OracleWebLogic/samples/12212-oradb-medrec/demo_oracle.ddl

If you are into database development, you can find more Oracle Database examples on GitHub.

Building MedRec Docker image

Make sure you have the store/oracle/weblogic image by doing a pull:

$ docker pull store/oracle/weblogic:12.2.1.2

The GitHub project that has the Dockerfiles and scripts to deploy the MedRec application are under ~/docker-images/OracleWebLogic/samples/12212-oradb-medrec. Clone the docker-images repository into your environment, open a terminal, and go into folder 12212-oradb-medrec.

$ git clone --depth 1 https://github.com/oracle/docker-images.git
$ cd docker-images/OracleWebLogic/samples/12212-oradb-medrec

The Dockerfile extends the WebLogic image, installs the WebLogic Supplemental Quick installer, and defines a command to invoke the shell script startSamples.sh at runtime.

Before continuing, make sure you download the WebLogic Server 12.2.1.2 Supplemental Quick Installer from OTN, and drop the zip file (without extracting it!) into folder 12212-oradb-medrec.

This sample has a file called startSample.sh that runs the following operations:

  1. Calls run_samples.sh script which invokes WLST scripts to build the MedRec domain and deploy the MedRec application.
  2. Invokes medrec-ds-deploy.py to configure a Generic Data Source MedRecGlobalDataSourceXA with properties defined in oradatasource.properties, to connect to the Oracle Database running in a container as described above.  
  3. Finally the script starts the WebLogic Server.

Edit the 12212-oradb-medrec/container-scripts/oracledatabase.properties, set the Oracle Thin XA driver, the Database URL, user and password to connect to the Oracle Database container we created before.

domainname=medrec
domainhome=/u01/oracle/wlserver/samples/domains/medrec
admin_name=MedRecServer
dsname=MedRecGlobalDataSourceXA
dsdbname=ORCLCDB
dsjndiname=jdbc/MedRecGlobalDataSourceXA
dsdriver=oracle.jdbc.xa.client.OracleXADataSource
dsurl=jdbc:oracle:thin:@//xxx.xxx.xxx.x:1521/ORCLCDB
dsusername=system
dspassword=LetsDocker

dstestquery=SELECT * FROM DUAL
dsmaxcapacity=1

Edit the Dockerfile and change the FROM line to:

FROM store/oracle/weblogic:12.2.1.2

Now we are ready to build the 12212-oradb-medrec image:

$ cd ~/docker-images/OracleWebLogic/samples/12212-oradb-medrec/
$ docker build -t 12212-oradb-medrec . 

We have now built all necessary images to run this sample. Run the docker images command to see the following images available in your environment:

Create and run a MedRec Docker container

Run the container from the image we built in the step before

$ docker run -d -it -p 7011:7011 12212-oradb-medrec

To look at the progress of the run and obtain the ip-address of the container

$ docker logs -f <container id> 

Now we are ready to test our deployed application and verify that the Data Source is actually connecting to our Oracle database container. Start the WebLogic Admin Console using localhost or the container ip-address noted above, weblogic/welcome1 as user name and password to log onto the console.

http://localhost:7011/console 

Navigate to the Data Source monitoring page

Services -> DataSources -> MedRecGlobalDataSourceXA -> Monitoring

 

Test the MedRec Application

You should now be able to access the MedRec application running on http://localhost:7011/medrec/. If everything worked fine, you should see this:

 

Summary

Oracle database and WebLogic on Docker is all about automating development, test operations, and automating production operations. Developing your Java applications to this platform give you the perfect environment to develop, and test with a rich set of features to configure, debug and monitor. Once your application tests have passed, you will have the building blocks to move applications into production!

The Oracle Cloud offers Container Cloud Service, and Application Container Cloud Service which manage these containers. Experiment with them by going to cloud.oracle.com/tryit, we are offering $300 in free credits which will be added to new Cloud accounts.

Join the discussion

Comments ( 1 )
  • Pascal Fuget Tuesday, November 14, 2017
    I've tried to use the oracle database images but I got issues running in docker. Very long download and even longer build and start to finally shutdown the process by lack of time. So I decided to use mysql in place and I have used last release of weblogic 12.2.1.3. I also changed the process to create tables and import data by using the medrec provided mechanism ant -db=mysql db.migrate because the DDL provided is not good for the object model. And now I've my container weblogic medrec using mysql in another container working fine. I can provide you the git project if you want to add it. I let the choise to use derby mysql or oracle database. You can also decide to use any database as long as you provide the database.properties in the database-migration/properties directory. Let me know if you want it.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.