I've previously summarized the steps to deploy Db2 in a Linux environment.
[Note] Db2 installation procedure summary (Linux) https://qiita.com/Haruka-Ogawa/items/9576399209b32f3016ea
Db2 has been available as a Docker version since 2017, You can use the Db2 environment more easily by pulling from the Docker store.
This time, I will summarize the procedure to get the Db2 container of Docker.
Have Docker installed on your PC. This time, I have installed Docker v19.03.12 on my Mac PC.
$ docker -v
Docker version 19.03.12, build 48a66213fe
First, get the Db2 image.
Use the ** docker pull ** command to get the image. Open the link below and copy the ** docker pull ** command to get the Db2 image on the right side of the screen.
https://hub.docker.com/r/ibmcom/db2
Execute the copied ** docker pull ** command.
$ docker pull ibmcom/db2
Using default tag: latest
latest: Pulling from ibmcom/db2
524b0c1e57f8: Pull complete
e7a9171c839a: Pull complete
f4447742b873: Pull complete
db90696d3502: Pull complete
6acc1312ab24: Pull complete
67e9a72bc07a: Pull complete
2b9e6b7678c7: Pull complete
Digest: sha256:cf95dd272a4f99d7f9119945ecad04b64ad3a2badc8a6682f1105aa87279da60
Status: Downloaded newer image for ibmcom/db2:latest
docker.io/ibmcom/db2:latest
[Reference] Docker documentation: pull https://docs.docker.jp/engine/reference/commandline/pull.html
Display the image list acquired by the ** docker images ** command and display it. Confirm that the db2 image has been obtained.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ibmcom/db2 latest d6b3abc02d57 2 months ago 2.69GB
[Reference] Docker documentation: images https://docs.docker.jp/engine/reference/commandline/images.html
Execute the ** docker run ** command to create and start the Db2 container. The command I ran this time is based on the guide on Docker Hub: ibmcom / db2.
$ docker run -itd --name mydb --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=passw0rd -e DBNAME=testdb -v /Users/ogawa/db2fs:/database ibmcom/db2
67070db8cf20d82a9be8b45454eb1d5239c6c4d33b685c8ab9503a3bcc84e68b
[Reference] Docker Hub: ibmcom / db2 https://hub.docker.com/r/ibmcom/db2
[Reference] Docker documentation: run https://docs.docker.jp/engine/reference/commandline/run.html
Check the container log with the ** docker logs ** command Confirm that the container has been created and started.
$ docker logs -f mydb
(*) Previous setup has not been detected. Creating the users...
(*) Creating users ...
(*) Creating instance ...
DBI1446I The db2icrt command is running.
DB2 installation is being initialized.
Total number of tasks to be performed: 4
Total estimated time for all tasks to be performed: 309 second(s)
Task #1 start
Description: Setting default global profile registry variables
Estimated time 1 second(s)
Task #1 end
Task #2 start
Description: Initializing instance list
Estimated time 5 second(s)
Task #2 end
Task #3 start
Description: Configuring DB2 instances
Estimated time 300 second(s)
Task #3 end
Task #4 start
Description: Updating global profile registry
Estimated time 3 second(s)
Task #4 end
The execution completed successfully.
For more information see the DB2 installation log at "/tmp/db2icrt.log.77".
DBI1070I Program db2icrt completed successfully.
09/09/2020 03:16:06 0 0 SQL1032N No start database manager command was issued.
SQL1032N No start database manager command was issued. SQLSTATE=57019
(*) Cataloging existing databases
ls: cannot access /database/data/db2inst1/NODE0000: No such file or directory
(*) Applying Db2 license ...
LIC1402I License added successfully.
LIC1426I This product is now licensed for use as outlined in your License Agreement. USE OF THE PRODUCT CONSTITUTES ACCEPTANCE OF THE TERMS OF THE IBM LICENSE AGREEMENT, LOCATED IN THE FOLLOWING DIRECTORY: "/opt/ibm/db2/V11.5/license/en_US.iso88591"
(*) Saving the checksum of the current nodelock file ...
(*) Updating DBM CFG parameters ...
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
No Cgroup memory limit detected, instance memory will follow automatic tuning
(*) Remounting /database with suid...
(*) Nothing appears in the Db2 directory. will skip update/upgrade.
(*) Code level is the same. No update/upgrade needed.
DB2 State : Operable
DB2 has not been started
Starting DB2...
09/09/2020 03:16:35 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(*) User chose to create testdb database
(*) Creating database testdb ...
DB20000I The CREATE DATABASE command completed successfully.
DB20000I The ACTIVATE DATABASE command completed successfully.
09/09/2020 03:18:38 0 0 SQL1026N The database manager is already active.
SQL1026N The database manager is already active.
### Enabling LOGARCHMETH1
Database Connection Information
Database server = DB2/LINUXX8664 11.5.4.0
SQL authorization ID = DB2INST1
Local database alias = TESTDB
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
### Restarting DB2
09/09/2020 03:18:46 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
09/09/2020 03:18:51 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
### Making backup directory and performing backup
Backup successful. The timestamp for this backup image is : 20200909031855
(*) Applying autoconfiguration for instance ...
Database Connection Information
Database server = DB2/LINUXX8664 11.5.4.0
SQL authorization ID = DB2INST1
Local database alias = TESTDB
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
DB20000I The SQL command completed successfully.
09/09/2020 03:19:15 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
09/09/2020 03:19:20 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(*) Skipping TEXT_SEARCH setup for database testdb because TEXT_SEARCH is not configured for the instance ...
ssh-keygen: generating new host keys: RSA1 RSA DSA ECDSA ED25519
(*) All databases are now active.
(*) Setup has completed.
FALSE
2020-09-09-03.19.20.117938+000 I223959E393 LEVEL: Warning
PID : 14939 TID : 139881437169536 PROC : db2start
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
FUNCTION: DB2 UDB, base sys utilities, sqleReleaseStStLockFile, probe:16076
MESSAGE : Released lock on the file:
DATA #1 : String, 50 bytes
/database/config/db2inst1/sqllib/ctrl/db2strst.lck
2020-09-09-03.19.37.389298+000 I224353E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.20.07.369457+000 I224774E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.20.37.353793+000 I225195E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.21.07.337071+000 I225616E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.24.02.151703+000 I226037E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.24.02.031095+000 I226458E419 LEVEL: Warning
PID : 14947 TID : 140530998568704 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 14 EDUNAME: db2wlmt 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
[Reference] Docker documentation: logs https://docs.docker.jp/engine/reference/commandline/logs.html
Display the list of containers with the ** docker ps ** command and Check the status of the Db2 container.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67070db8cf20 ibmcom/db2 "/var/db2_setup/lib/…" About an hour ago Up About an hour 22/tcp, 55000/tcp, 60006-60007/tcp, 0.0.0.0:50000->50000/tcp mydb
[Reference] Docker documentation: ps https://docs.docker.jp/engine/reference/commandline/ps.html
The ** docker exec ** command can execute any command inside the container. Start bash and switch to db2inst1 to enter the db2 environment.
$ docker exec -ti mydb bash -c "su - db2inst1"
Last login: Wed Sep 9 04:48:57 UTC 2020
[Reference] Docker documentation: exec https://docs.docker.jp/engine/reference/commandline/exec.html
Make sure that you can execute the Db2 command.
--Check the version of db2
Execute the ** db2level ** command to check the Db2 version.
[db2inst1@67070db8cf20 ~]$ db2level
DB21085I This instance or install (instance name, where applicable:
"db2inst1") uses "64" bits and DB2 code release "SQL11054" with level
identifier "0605010F".
Informational tokens are "DB2 v11.5.4.0", "s2006161200", "DYN2006161200AMD64",
and Fix Pack "0".
Product is installed at "/opt/ibm/db2/V11.5".
--Database connection
At the time of executing the ** docker run ** command, the database * testdb * has been created. Connect to the database * testdb * with the ** connect ** command.
[db2inst1@67070db8cf20 ~]$ db2 connect to testdb
Database Connection Information
Database server = DB2/LINUXX8664 11.5.4.0
SQL authorization ID = DB2INST1
Local database alias = TESTDB
--Create table
Let's create a table * TBL1 * in the database * testdb *.
[db2inst1@67070db8cf20 ~]$ db2 "CREATE TABLE TBL1(COL1 INTEGER, COL2 VARCHAR(50))"
DB20000I The SQL command completed successfully.
--Database disconnection
Disconnect from the database * testdb * with the ** terminate ** command.
[db2inst1@67070db8cf20 ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
I executed the Db2 command and confirmed that it can be operated.
Use the exit command when exiting the container.
[db2inst1@67070db8cf20 ~]$ exit
logout
To start / stop the created container, Use the ** docker start ** command and the ** docker stop ** command.
Start the Db2 container (* mydb *) with the ** docker start ** command.
$ docker start mydb
mydb
[Reference] Docker documentation: start https://docs.docker.jp/engine/reference/commandline/start.html
Use the ** docker stop ** command to stop the Db2 container (* mydb *).
$ docker stop mydb
mydb
[Reference] Docker documentation: stop https://docs.docker.jp/engine/reference/commandline/stop.html
This time, I tried pulling Db2 provided as a Docker container.
If you have a PC with Docker installed, you can use the Db2 environment very easily, The work itself was completed in about 10 minutes, so I felt it would be convenient if I wanted to check the operation of Db2 for a while.
Db2 and Docker https://www.ibm.com/blogs/solutions/jp-ja/db2-docker/
Docker Hub:ibmcom/db2 https://hub.docker.com/r/ibmcom/db2
Recommended Posts