Hello. This time, I will show you how to set up and use IBM's Db2 container, which is easy to set up and process data when you want to use it for a little development or testing.
This container is actually used by me for project development and is very convenient, so I highly recommend it.
Data management software (DBMS) that IBM has been selling commercially since 1983. I think that it is basically software that is often used by enterprises, but we have published a container on Docker Hub, which can be used for free with restrictions.
Getting Started Let me introduce you. First of all, the environment is Win10, but you can do it on Mac without any inconvenience. Well, you don't need to worry about Windows-dependent settings or environment at all (it is natural that it is not OS-dependent because it is a container). Both Mac and Linux should work if you follow this article.
Now let's drop the Db2 container image into your environment. Of course, you will need to register for Docker Hub, so please do that. The Docker Hub page is here (https://hub.docker.com/r/ibmcom/db2).
Type the following command in PowerShell, CMD, Git Bash, or Terminal. Pull the latest version.
$ docker pull ibmcom/db2:11.5.4.0
The download will start and the container image will drop. It has a capacity of about 2.69GB, so I think it will take some time to download.
When the pull is completed, the following will be displayed.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ibmcom/db2 11.5.4.0 d6b3abc02d57 3 months ago 2.69GB
Configuration information is required to use Db2. The name of the database, the password, etc. I have prepared a sample below.
env.list
LICENSE=accept
DB2INSTANCE=db2inst1
DB2INST1_PASSWORD=password
DBNAME=USERDB
BLU=false
ENABLE_ORACLE_COMPATIBILITY=false
TO_CREATE_SAMPLEDB=false
PERSISTENT_HOME=true
HADR_ENABLED=false
ETCD_ENDPOINT=
ETCD_USERNAME=
ETCD_PASSWORD=
Now, let's execute the container based on the above information.
$ docker run --name test-db --detach --privileged=true -p 50000 --env-file env.list ibmcom/db2:11.5.4.0
docker stop test-db
.When run, the docker container runs in the background. Setting up the db container takes quite some time. It will be completed in a few minutes. I don't know when it's over just by waiting, so I'll output the container log.
$ docker logs -f test-db
A long log will flow, and when (*) Setup has completed.
arrives, it is complete.
In fact, behind the scenes when the container runs
/var/db2_setup/lib/setup_db2_instance.sh
The shell script is executed.
This shell is behind
/var/db2_setup/include/db2_common_functions
Shell is executed, and this shell sets up the DB.
further
/var/custom
By creating a directory called, you can execute a shell script that stores sql files and csv files in it and stores the data in the database as the initial value.
I will introduce it in another article.
Now that we have created a DB container, let's actually go into it and insert tables and data. You can enter the DB container with the following command.
$ docker exec -it test-db bash -c "su - db2inst1"
$ db2 connect to userdb
Now I'm in Db2.
Let's check the table as a trial.
$ db2 "list tables"
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
0 record(s) selected.
Of course there is no table, but it was displayed properly.
Next, create a table and insert data.
$ db2 "create table users(id varchar(36) not null primary key, name varchar(20) not null)"
DB20000I The SQL command completed successfully.
$ db2 "insert into users values('65c694ba-7574-461b-935d-368facca3544', 'hogefuga')"
DB20000I The SQL command completed successfully.
$ db2 "select * from users"
ID NAME
------------------------------------ --------------------
65c694ba-7574-461b-935d-368facca3544 hogefuga
1 record(s) selected.
You can insert data like this.
It's very convenient to start the database when you want it and set it up easily. However, it seems that the startup is a little slow, but However, it is easy to customize and is very useful for testing and development.
Recommended Posts