Setting up WSO2-IS with Docker Oracle
Docker provides containerization to applications for isolation on top of a shared operating system. This is ideal for developers and teams looking to get started and experimenting with container-based applications. Docker provides an integrated container-native development experience with the largest library of community and certified Linux and Windows content from Docker Hub.
In this guide we will see how to install Oracle Database inside a Docker container and connect with WSO2 Identity Server. First let’s install Docker application in the system. In this guide i am using Ubuntu-16.04 as my system.
Installing Docker on Ubuntu-16.04
In order to install Docker first we need to add the official Docker repository. Add the GPG key for the official Docker repository.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the docker repository to the APT sources.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Update the package databases with the Docker packages from the newly added repository.
sudo apt-get update
Make sure you are about to install from the Docker repository instead of the default Ubuntu 16.04 repository (Latest repository versions are up to date in the Docker repository).
apt-cache policy docker-ce
Install the Docker.
sudo apt-get install -y docker-ce
Docker should be installed now, the daemon started, and the process enabled to start on boot. Run the following command to check it.
sudo systemctl status docker
Now that the docker is started let’s check whether we can download images from Docker Hub.
docker run hello-world
Installing Oracle Binaries inside Docker
For this we need to clone official oracle database support of docker from the github. https://github.com/oracle/docker-images.
This repository contains Sample Docker build files to facilitate installation, configuration, and environment setup for DevOps users.
So let’s download it into a directory called /Test
git clone https://github.com/oracle/docker-images.git
Now inside the Test/ directory you could see the cloned docker-images/ directory.
We are going to install oracle database as a single instance (can also install as a RAC), so navigate to the following directory.
In order to run the build scripts we need to place the oracle binaries inside this dockerfiles/ under the relevant version.
For this download the oracle binaries from the following location. http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html
I have downloaded the Oracle Database 12c Release 2 (188.8.131.52) and placed the zip file inside the dockerfiles/184.108.40.206/ directory.
Now we need to run the following build script from the dockerfiles/ directory with the version to build.
./buildDockerImage.sh -v 220.127.116.11 -e
More details about building options can be found at https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance
Now the docker image for oracle docker is build. Type the following command to list all the docker images in your system.
Now let’s run the oracle/database docker image. I have build the enterprise image oracle/database:18.104.22.168-ee.
docker run --name <container name> \
-p <host port>:1521 -p <host port>:5500 \
-e ORACLE_SID=<your SID> \
-e ORACLE_PDB=<your PDB name> \
-e ORACLE_PWD=<your database passwords> \
-e ORACLE_CHARACTERSET=<your character set> \
-v [<host mount point>:]/opt/oracle/oradata \
In our case it would be something like this
docker run --name oracle -p 1521:1521 -p 5500:5500 \
-e ORACLE_SID=wso2carbon \
-e ORACLE_PWD=wso2carbon \
-e "TZ=Asia/Colombo" -v /etc/timezone:/etc/timezone:ro \ oracle/database:22.214.171.124-ee
Here the timezone and the copying the timezone file into the docker is important, if not your docker clock won’t be synced with your system clock.
Now we have created the docker container for the oracle docker instance.
Let’s login in to the docker container command line.
docker exec -it oracle "bash"
Since we haven’t provided the ORACLE_PDB while creating the oracle docker container our database name will be the same as the ORACLE_SID(System Identifier). SID is the unique name for the oracle database instance, one database can have multiple instances connected with it.
Now let’s create a user by logging in as the system admin.
sqlplus wso2carbon/wso2carbon as sysdba
Create a user admin and grant permissions.
alter session set "_ORACLE_SCRIPT"=true;
create user admin identified by admin;
grant create session to admin;
grant all privileges to admin;
alter user admin quota 100M on USERS;
Now we have completed the oracle docker database setup. Let’s now update the datasources configuration in the WSO2 Identity Server side to connect with this database. Update the datasources configuration in the <PRODUCT_HOME>/repository/conf/datasources/master-datasources.xml file as shown below.
<description>The datasource used for registry and user manager</description>
To successfully initiate the connection we need to do one more thing. We need to have the relevant oracle jdbc driver deployed in the Identity Server.
Dowload the Oracle Database 126.96.36.199 JDBC Driver from the following link.
Copy the ojdbc8.jar to the <PRODUCT_HOME>/repository/components/lib/ directory.
Remove the old database driver from the <PRODUCT_HOME>/repository/components/dropins/ directory.
Since we have setup the with a fresh database for the first time we need to run the oracle database scripts to create the relevant tables. So in order to do that start the Identity Server setup option.
sh bin/wso2server.sh -Dsetup
All done, now you can view the data tables created an their entries by connecting with Oracle SQL Developer. Follow this guide on setting up the Oracle SQL Developer.
If there is any issue in installing Oracle Database in Docker feel free to comment.