Public | Automated Build

Last pushed: a year ago
Short Description
2. Prepares the environment to create a DB2 instance on an existing DB2 installation
Full Description

Supported tags and respective Dockerfile links

What is DB2?

IBM DB2 is a family of database server products developed by IBM. These products all support the relational model, but in recent years some products have been extended to support object-relational features and non-relational structures, in particular XML.

Historically and unlike other database vendors, IBM produced a platform-specific DB2 product for each of its major operating systems. However, in the 1990s IBM changed track and produced a DB2 "common server" product, designed with a common code base to run on different platforms.

What is a DB2 instance?

A DB2 instance is a running process that controls the security at the higher level, listens on a specific port, controls the databases it hosts, and many other operations related to database administration.

Set of images

This image is part of a set of images to create your DB2 environment:

This is the stack of images:

+----------------+
|   db2-sample   |  <-- Sample database (db2sampl)
+----------------+
|    db2inst1    |  <-- Default instance created (db2inst1:50000)
+----------------+
|  db2-instance  |  <-- Environment to create an instance
+----------------+
|   db2-install  |  <-- DB2 Express-C installed
+----------------+

How to use this image

This image will prepare the environment to create a DB2 instance. It uses the angoca/db2-install image that installs DB2.

Once the installation was done, this image could be loaded. This image will populate the previous image with some scripts to ease the instance creation. The script that creates the instance follows the instructions of a response file. The instance by default is db2inst1 listening on port 50000 installed in the /home/db2inst1 directory.

The process is performed in two steps:

  • First, the image is provided with the necessary scripts (build).
  • Second, in the image, a DB2 instance can be created interactively (run).

Please, check the Travis-CI execution to see how this image is build.

Build

The build process can be done via a pull or directly from the sources via build. This will create the image that will be ready to run.

Pull from Docker:

sudo docker pull angoca/db2-instance:latest

Build from sources

git clone https://github.com/angoca/db2-docker.git
sudo docker build instance/expc

Run

The execution of a new container should be done in privilege mode, interactive with a seudo TTY. For example:

sudo docker run -i -t --privileged=true --name="db2inst1" -p 50000:50000 angoca/db2-instance

The name of the container will be db2inst1.

You can try the following line in order to not use privileged mode:

sudo docker run -i -t --ipc="host" --cap-add IPC_LOCK --cap-add IPC_OWNER --name="db2inst1" -p 50000:50000 angoca/db2-instance

Once the container is running, the console is active under the /tmp/db2_conf directory. In this directory you will find a DB2 response file and a script to create an instance. The DB2 response file is configured to create a DB2 instance called db2inst1 listening on port 50000. If you want to change these or other properties, you just need to modify the response file or call the createInstance script with another username, for example:

./createInstance

Or for a specific instance name

./createInstance myinst

It will run db2isetup, and then you can change to the instance user and start the instance. Once there, you can create the database, or perform other configuration changes.

Once you have finished the configuration, you can leave the container running by typing:

Ctrl + P + Q

Local file system

If you want to have an independent execution environment, but a shared storage, you can mount a local directory in the images. It is recommended that you mount the /home directory and create all instances under this structure. This will store the home directories of the instances in the host, instead of in the containers.

/home <-- /db2 locally in the host
  /db2inst1 <-- Home directory for instance db2inst1
  /db2inst2 <-- Home directory for instance db2inst2

The previous distribution works only if you create different instance users across all containers. (It is not necessary to have one instance per container, but different instances across all containers when using host storage.)

It is very important that you mount this file system before creating the instance.

sudo mkdir /db2
sudo docker run -i -t --privileged=true --name="db2inst1" -p 50000:50000 -v /db2:/home angoca/db2-instance

NOTE: If you use automatic storage in DB2, and the database creation does not specify any path, the data will be also stored under /home. Instead, if you specify specific paths for your containers, make sure where they are stored (in the containers or in the host via mount).

Daemon

Once the instance has been created, you can run the DB2 instance as a Docker daemon.

sudo docker start

Once the container with DB2 is running, it can be used to create, populate, manipulate and perform other activities with databases.

If you want to access the console, you need to do an attach to the container

sudo attach db2inst1

Acknowledgements

The design of this image is based on the following DB2-Docker images:

And the posts of the following blogs:

Advantages of these images

The advantages to use this image instead of the other are:

  • The DB2 binary file is download semi-automatically. Just the wiki has to have the valid link. The other images requiere to modify the image with a valid link or to have DB2 installer/binaries locally in the machine.
  • This image has a mechanism to create more instances with a simple script that uses a response file. The instance owner can have any name; it is not limited to db2inst1 or something like db2instX where X is a number.
  • The environment can be configured in different ways. It is not limited to a fixed instance or database. The set of images provide different levels of flexible configuration.
  • The images are published in Docker in the angoca repository. The image is not created on the fly. The basic images are created from Dockerfiles, the other were published in the repository with the instance or database already created. As part of the publish, a corresponding documentation is provided.
  • The images can be found by performing a search in Docker. This allows to have a better visibility.
  • It was developed by a DB2 DBA. This makes this image appropriate not only for developers but also for DBAs and SysAdmins.
  • The complete installation and configuration is divided in different images. This makes the solution more flexible and easy to extent.
  • There is documentation. This is very important for new users to understand the structure of the
    images.

User Feedback

Issues

If you have any problems with or questions about this image, please contact us through a GitHub issue.

You can also reach the mainteiner via Twitter @angoca.

Contributing

You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.

Before you start to code, we recommend discussing your plans through a GitHub issue, especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing.

Docker Pull Command
Owner
angoca
Source Repository

Comments (6)
magm3333
8 months ago

Add extra information to previous comment:

Initial run:
sudo docker run -i -t --privileged=true --name="db2inst1" -p 50000:50000 -v ~/docker/db2:/home angoca/db2-instance
(Inside container I run: ./createInstance in order to create default instance)

After, I testing connection from Data Studio.

Later:
sudo docker start db2inst1
sudo docker attach db2inst1

Here I have problems

regards
Mariano

magm3333
8 months ago

Hi Andres, I am trying to use local file system volumes.
I create instance and run ok, but when I rerun container, the instance and user not exists, however file system is mounted correctly.
You can help me?
Best regards
Mariano

rithwik572
9 months ago

I am trying to connect to port 50000 $ elinks http:localhost//50000 but it throws error : unable to connect

angoca
a year ago

@reetesh if you use the server_t images, the installer will download the most recent fixpack, and then you can apply the license you have. Otherwise, DB2 will be in trial for 90 days.

reetesh
2 years ago

can we use db2 enterprise server edition in docker image

rachit1arora
3 years ago

Hello

I have done some experiments around db2 on docker and was able to start db2 in a docker container without --privilege=true but using limited privileges
I have have published my findings in a blog here
http://db2indocker.blogspot.in/
Please check it out and let me know your comments