Over a million developers have joined DZone.

Docker Containers and IBM DB2 Warehouse — An Introduction

DZone 's Guide to

Docker Containers and IBM DB2 Warehouse — An Introduction

An introduction to Docker Containers.

· Microservices Zone ·
Free Resource

In my twenty years in IT, the containerization of applications, namely through Docker, is maybe the technology with the fastest adoption rate I have ever seen. The first release of Docker was delivered only five years ago back in 2014. Since then, containers have become the architecture of choice for many IT projects, especially when used together with orchestration through Kubernetes.

IBM has also containerized most of the database offerings, namely the Db2 Warehouse family. IBM Db2 Warehouse is deployed as a Docker container. This allows you to use a variety of platforms, such as Intel x86, IBM Power, and Linux on z. Db2 Warehouse can be also deployed on IBM Cloud Pak for Data, IBM Cloud, or any virtual private cloud like AWS, Microsoft Azure and more.

You can download the free IBM Db2 Warehouse Developer Edition from Docker Hub: https://hub.docker.com/_/ibm-db2-warehouse-dev. Alternatively, try a hands-on lab on Db2 Warehouse and Docker. This lab allows you to work with a Db2 Warehouse deployment and guide you through some of the most common Docker commands.

If you are an experienced Db2 administrator but did not work much with containers yet, there are some (few) things to learn. Some of the hurdles I came across when starting to work with Docker were:

  • Installation/ Deployment of Db2 Warehouse is done using Docker commands rather than  db2_install  or  db2setup  commands.
  • You need to know which environment you are working in: Are you already logged on to the Docker container, or are you still on the host running Docker?
  • How to copy files from the container to the host and vice-versa.

Let’s start with the deployment of Db2 Warehouse. Luckily, this is a very easy process, once you have understood some of the basics of Docker. The deployment is also well documented in the Db2 Warehouse Knowledge Center for all supported platforms, including Kubernetes.

The following command example will use the  docker run  command to deploy a Db2 Warehouse Developer Edition.

docker run -d -it --privileged=true --net=host --name=Db2wh -v /mnt/clusterfs:/mnt/bludata0 -v /mnt/clusterfs:/mnt/blumeta0 store/ibmcorp/db2wh_ce:<version>-db2wh_devc-linux

This command creates a Db2 Warehouse container (using the name Db2whas provided using the
 —name  command option). It will also create and mount the file systems used by the container (specified through the  -v / —volume  command option).

The  docker run  command itself is not very verbose. But you can follow the progress of the deployment using the command

docker logs --follow Db2wh

Once the deployment (which includes creating a Db2 instance and BLUDB database) has finished, you can work with the Db2 warehouse installation.

After the docker run command has completed, the Db2 Warehouse container is started automatically, so you can immediately log on to the container. Starting and stopping of Db2 is done differently in a Docker environment compared to a traditional Db2 installation. To start a Db2 Warehouse container Db2wh issue:

docker start Db2wh

To stop the same container, use:

docker stop Db2wh

Once Db2 Warehouse is started, you can log on to the container. Use the following Docker command:

docker exec -it Db2wh su – bluadmin

This will open an interactive terminal inside the container and log you on as the BLUADMIN user. Once you are logged in to the container, you can run Db2 commands and statements as you would in a “traditional” Db2 environment. Also, tools like  db2pd  or  dsmtop  can be run in the container. If you are used to look at Db2 diagnostic information, you probably have worked with the db2diag.log file before. In Docker environments, you might also want to look at the Db2wh_local.log. This file is located in directory /var/log and provides information on the startup of the Db2 Warehouse container.

In the container itself, you will probably notice the different file system structure, for example when looking for the home directory of the Db2 instance. If you run the docker run command from above, you will find the sqllib directory under the /mnt/blumeta0/home/db2inst1 directory. On the host itself, you will see these directories in the /mnt/clusterfs filesystem.

In addition to the Db2 commands that are available on all form factors, Db2 Warehouse provides support tools. These tools are similar to the commands provided in IBM Netezza appliances. For example, if you are used to the Netezza  nzsql  command, you will probably prefer thedbsql command over the traditional Db2 command line processor.

You can get a list of the available support commands by issuing the following command (from outside the Db2 container):

docker exec -it Db2wh commands 

One of the many useful commands to try is:

docker exec -it Db2wh db_size

This command will provide information on the size of the database and all the tables in it.

One of the tasks that you often need to do within Docker is moving files between the containers and the host system. You can use the  docker cp  command for this. For example, to copy the file Db2wh_local.log from the container (directory /var/log) to the /tmp directory of the local host, issue:

docker cp Db2wh:/var/log/Db2wh_local.log /tmp

The Db2 Warehouse client can be also downloaded from Docker hub: https://hub.docker.com/_/ibm-db2-warehouse-client-container. The deployment of the client is done through the  docker run  command. For example, with the following command, we will deploy the Db2 Warehouse client, call the Docker container “client”, and will already catalog the database we want to connect to (using the  -e /--environment option).

docker run -dit --net=host -v /mnt/tools:/mnt/clientdir -v /mnt/clusterfs/home/db2inst1:/mnt/blumeta0/home/db2inst1 --name=client -e REMOTE_DB=proddb.acme.org:50001 store/ibmcorp/db2wh_ce:<version>-db2wh_client-linux 

Once the Docker deployment has finished, you can work with the Db2 Warehouse client container. To log on to the container, issue:

docker exec -it client cli

You will be logged on to the Db2 command-line interface. You can connect to the database that you cataloged during the deployment. Or catalog additional databases using the  db_catalog  command:

db_catalog --add <DB server>:<port> [--alias <database alias>] [--ssl]
docker ,db2 ,tutorial ,microservices

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}