Configure Database DB2 with Docker and use DB2 as the DB Type with WSO2 Identity Server.

Shanika Wickramasinghe
3 min readAug 27, 2019

--

First you need to install docker in your local machine or in the remote instance that you use to configure DB2. Use the below commands to do that.

If you love to see how to configure DB2 Database with Docker with a youtube video, you can also watch my video tutorial published on Briztol Tech Academy Youtube channel using link https://youtu.be/j3aiOdhSXVQ. To see more videos like this please subscribe to the youtube channel Briztol Tech Academy.

Installing Docker

To ensure the downloads are valid, add the GPG key for the official Docker repository to your system

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

update the package database with the Docker packages from the newly added repo

sudo apt-get update

Make sure you are about to install from the Docker repo

apt-cache policy docker-ce

Install Docker

sudo apt-get install -y docker-ce

Check the docker status

sudo systemctl status docker

When you check the status if it shows as below. Docker is succesfully installed in your system.

● docker.service — Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019–08–27 08:31:15 UTC; 1min 16s ago
Docs: https://docs.docker.com
Main PID: 5876 (dockerd)
CGroup: /system.slice/docker.service
└─5876 /usr/bin/dockerd -H fd:// — containerd=/run/containerd/containerd.sock

Install DB2 inside Docker

Use the below command to do this

sudo docker run -itd — name db2 privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=db2inst1 -e DBNAME=test -v /home/ubuntu/DB2:/database ibmcom/db2

Output will be something similar to below

sudo docker ps -a

sudo docker exec -i -t db2 /bin/bash

su — db2inst1

db2start

Output can be checked from the below image.

Create a DB2 Database

Use the below commands to create the database

db2 create database test3

db2 connect to test3 user db2inst1 using db2inst1

Create tables pointing the DB2 Database

Use the DB client Dbeaver to connect to the created Database. Once connecting you need to download the matching db2 jar to your machine from where you access the DB viewer and point that jar location in the Driver settings of the DB viewer.

Password used in the above image is db2inst1.

Once you connect you can select the DB2-test2 from the db clients left hand side.

Get a new sql editor by right clicking on the DB2-test2. Then copy the db2.sql script that you want to execute against the database test2 and execute the script.

Note : If you get any error related to symbol / when you execute wso2 IS related db2 scripts with DBviewer in the script , then if you have / charactors replace them with ; before executing

Configure DB2 as the DB Type in WSO2 Identity Manager

Download the PostgreSQL driver and copy it to <IS-HOME>/repository/components/lib

Add the data source configuration in the <IS-HOME>/repository/conf/datasources/master-datasource.xml as below

<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type=”RDBMS”>
<configuration>
<url>jdbc:db2://localhost:50000/test2</url>
<username>db2inst1</username>
<password>db2inst1</password>
<driverClassName>com.ibm.db2.jcc.DB2Driver</driverClassName>
<maxActive>80</maxActive>
<maxWait>360000</maxWait>
<minIdle>5</minIdle>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM SYSIBM.SYSDUMMY1</validationQuery>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>false</defaultAutoCommit>
</configuration>

Then if you havent changed your default user store type your primary user store type will be embedded ldap and your DB type will be DB2.

--

--

Shanika Wickramasinghe

Senior Software Engineer and Freelance Technical Writer. I write about any Computer Science related topic. https://www.linkedin.com/in/shanikawickramasinghe