I am trying to create a db2 instance and a sample database using docker. Below is my docker compose entry:
db2:
image: icr.io/db2_community/db2
privileged: true
restart: always
environment:
LICENSE: accept
DB2INSTANCE: db2inst1
DB2INST1_PASSWORD: password
DBNAME: dbtest
BLU: false
TO_CREATE_SAMPLEDB: true
IS_OSXFS: true
REPODB: true
HADR_ENABLED: false
DOCKER_DEFAULT_PLATFORM: linux/amd64
ports:
- 50000:50000
volumes:
- db2:/database
platform: linux/amd64
The container creates fine as far as I can see (including the sample database)
2025-03-05 11:10:39 (*) Previous setup has not been detected. Creating the users...
2025-03-05 11:10:39 (*) Creating users ...
2025-03-05 11:10:40 (*) Creating instance ...
2025-03-05 11:11:03 DB2 installation is being initialized.
2025-03-05 11:11:03
2025-03-05 11:11:48 Total number of tasks to be performed: 4
2025-03-05 11:11:48 Total estimated time for all tasks to be performed: 309 second(s)
2025-03-05 11:11:48
2025-03-05 11:11:49 Task #1 start
2025-03-05 11:11:49 Description: Setting default global profile registry variables
2025-03-05 11:11:49 Estimated time 1 second(s)
2025-03-05 11:11:49 Task #1 end
2025-03-05 11:11:49
2025-03-05 11:11:49 Task #2 start
2025-03-05 11:11:49 Description: Initializing instance list
2025-03-05 11:11:49 Estimated time 5 second(s)
2025-03-05 11:12:09 Task #2 end
2025-03-05 11:12:09
2025-03-05 11:12:09 Task #3 start
2025-03-05 11:12:09 Description: Configuring DB2 instances
2025-03-05 11:12:09 Estimated time 300 second(s)
2025-03-05 11:15:29 Task #3 end
2025-03-05 11:15:29
2025-03-05 11:15:29 Task #4 start
2025-03-05 11:15:29 Description: Updating global profile registry
2025-03-05 11:15:29 Estimated time 3 second(s)
2025-03-05 11:15:29 Task #4 end
2025-03-05 11:15:29
2025-03-05 11:15:29 The execution completed successfully.
2025-03-05 11:15:29
2025-03-05 11:15:44 For more information see the DB2 installation log at "/tmp/db2icrt.log.268".
2025-03-05 11:15:44 DBI1446I The db2icrt command is running.
2025-03-05 11:15:44
2025-03-05 11:15:44
2025-03-05 11:15:44 DBI1070I Program db2icrt completed successfully.
2025-03-05 11:15:44
2025-03-05 11:15:44
2025-03-05 11:15:44 (*) Fixing /etc/services file for DB2 ...
2025-03-05 11:15:48 03/05/2025 11:15:48 0 0 SQL1032N No start database manager command was issued.
2025-03-05 11:15:48 SQL1032N No start database manager command was issued. SQLSTATE=57019
2025-03-05 11:16:10 (*) Cataloging existing databases
2025-03-05 11:16:10 ls: cannot access '/database/data/db2inst1/NODE0000': No such file or directory
2025-03-05 11:16:10 (*) Applying Db2 license ...
2025-03-05 11:16:10
2025-03-05 11:16:10 LIC1402I License added successfully.
2025-03-05 11:16:10
2025-03-05 11:16:10
2025-03-05 11:16:10 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/V12.1/license/en_US.iso88591"
2025-03-05 11:16:10 (*) Saving the checksum of the current nodelock file ...
2025-03-05 11:16:11 (*) Updating DBM CFG parameters ...
2025-03-05 11:16:21 DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
2025-03-05 11:16:21 successfully.
2025-03-05 11:16:24 DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
2025-03-05 11:16:24 successfully.
2025-03-05 11:16:28 DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
2025-03-05 11:16:28 successfully.
2025-03-05 11:16:28 No Cgroup memory limit detected, instance memory will follow automatic tuning
2025-03-05 11:16:28 (*) Remounting /database with suid...
2025-03-05 11:16:48 (*) Nothing appears in the Db2 directory. will skip update/upgrade.
2025-03-05 11:16:48 (*) Code level is the same. No update/upgrade needed.
2025-03-05 11:16:50
2025-03-05 11:16:50 DB2 State : Operable
2025-03-05 11:16:50 DB2 has not been started
2025-03-05 11:16:50 Starting DB2...
2025-03-05 11:16:50
2025-03-05 11:17:02 03/05/2025 11:17:02 0 0 SQL1063N DB2START processing was successful.
2025-03-05 11:17:02 SQL1063N DB2START processing was successful.
2025-03-05 11:17:02 (*) Creating repository database for DSM ...
2025-03-05 11:19:48 DB20000I The CREATE DATABASE command completed successfully.
2025-03-05 11:19:48 (*) User chose to create dbtest database
2025-03-05 11:19:48 (*) Creating database dbtest ...
2025-03-05 11:22:28 DB20000I The CREATE DATABASE command completed successfully.
2025-03-05 11:22:33 DB20000I The ACTIVATE DATABASE command completed successfully.
2025-03-05 11:22:37 03/05/2025 11:22:37 0 0 SQL1026N The database manager is already active.
2025-03-05 11:22:37 SQL1026N The database manager is already active.
2025-03-05 11:22:37 ### Enabling LOGARCHMETH1
2025-03-05 11:22:40
2025-03-05 11:22:40 Database Connection Information
2025-03-05 11:22:40
2025-03-05 11:22:40 Database server = DB2/LINUXX8664 12.1.1.0
2025-03-05 11:22:40 SQL authorization ID = DB2INST1
2025-03-05 11:22:40 Local database alias = DBTEST
2025-03-05 11:22:40
2025-03-05 11:22:40 DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
2025-03-05 11:22:40 SQL1363W One or more of the parameters submitted for immediate modification
2025-03-05 11:22:40 were not changed dynamically. For these configuration parameters, the database
2025-03-05 11:22:40 must be shutdown and reactivated before the configuration parameter changes
2025-03-05 11:22:40 become effective.
2025-03-05 11:22:40 ### Restarting DB2
2025-03-05 11:23:07 03/05/2025 11:23:07 0 0 SQL1064N DB2STOP processing was successful.
2025-03-05 11:23:07 SQL1064N DB2STOP processing was successful.
2025-03-05 11:23:18 03/05/2025 11:23:18 0 0 SQL1063N DB2START processing was successful.
2025-03-05 11:23:18 SQL1063N DB2START processing was successful.
2025-03-05 11:23:18 ### Making backup directory and performing backup
2025-03-05 11:23:25
2025-03-05 11:23:25 Backup successful. The timestamp for this backup image is : 20250305112324
2025-03-05 11:23:25
2025-03-05 11:23:25 (*) Applying autoconfiguration for instance ...
2025-03-05 11:23:30
2025-03-05 11:23:30 Database Connection Information
2025-03-05 11:23:30
2025-03-05 11:23:30 Database server = DB2/LINUXX8664 12.1.1.0
2025-03-05 11:23:30 SQL authorization ID = DB2INST1
2025-03-05 11:23:30 Local database alias = DBTEST
2025-03-05 11:23:30
2025-03-05 11:23:37 DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
2025-03-05 11:23:37 SQL1363W One or more of the parameters submitted for immediate modification
2025-03-05 11:23:37 were not changed dynamically. For these configuration parameters, the database
2025-03-05 11:23:37 must be shutdown and reactivated before the configuration parameter changes
2025-03-05 11:23:37 become effective.
2025-03-05 11:23:38 DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
2025-03-05 11:23:41 DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
2025-03-05 11:23:41 SQL1363W One or more of the parameters submitted for immediate modification
2025-03-05 11:23:41 were not changed dynamically. For these configuration parameters, the database
2025-03-05 11:23:41 must be shutdown and reactivated before the configuration parameter changes
2025-03-05 11:23:41 become effective.
2025-03-05 11:23:44 DB20000I The SQL command completed successfully.
2025-03-05 11:23:47 03/05/2025 11:23:47 0 0 SQL1064N DB2STOP processing was successful.
2025-03-05 11:23:47 SQL1064N DB2STOP processing was successful.
2025-03-05 11:23:57 03/05/2025 11:23:56 0 0 SQL1063N DB2START processing was successful.
2025-03-05 11:23:57 SQL1063N DB2START processing was successful.
2025-03-05 11:24:10 (*) Skipping TEXT_SEARCH setup for database dbtest because TEXT_SEARCH is not configured for the instance ...
2025-03-05 11:24:17 ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
2025-03-05 11:24:18 (*) All databases are now active.
2025-03-05 11:24:18 (*) Setup has completed.
Now if I use DBeaver to connect I can't see the sample db (should be called testdb):
I don't think it is a missing connection setting (as I get the same view using PHPStorm too):
I would expect to see the TESTDB schema in the list of schemas. If I go into the container and run db2sampl
to create the SAMPLE db I also can't see that. Is there a setting I need to change or is there something more fundamental wrong. I'm using a Macbook M2 Chip.
Quick Answer: Everything is fine, the database has been created, and you are connected to it.
Details are as follows:
version: '3.8'
services:
db2:
image: icr.io/db2_community/db2:latest
environment:
- LICENSE=accept
- DB2INSTANCE=db2inst1
- DB2INST1_PASSWORD=password
- DBNAME=dbtest
- BLU=false
- HADR_ENABLED=false
- SAMPLEDB=true
- REPODB=true
ports:
- "50000:50000"
volumes:
- db2:/database
restart: always
privileged: true
volumes:
db2:
driver: local
docker-compose up -d
Wait for a while... Probably 10 minutes or less...
Run command and view log
docker-compose logs -f db2
If you see the following message, it is complete.
...
db2_1 | Database Connection Information
db2_1 |
db2_1 | Database server = DB2/LINUXX8664 12.1.1.0
db2_1 | SQL authorization ID = DB2INST1
db2_1 | Local database alias = DBTEST
db2_1 |
db2_1 | DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
db2_1 | DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
...
TOOL: dbeaver
URL: jdbc:db2://localhost:50000/dbtest
You are connected to the dbtest database, but it is an empty database by default.
Menu SQL Editor
-> New SQL script
.
Enter the following SQL to create Table: STUDENTS
.
CREATE TABLE STUDENTS (
id INT GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
age INT,
grade VARCHAR(10),
email VARCHAR(100),
enrollment_date DATE
);
execute sql script
Enter the following SQL to insert data:
INSERT INTO STUDENTS (name, age, grade, email, enrollment_date)
VALUES
('DB2 Alice', 20, 'A', 'db2.alice@example.com', '2025-03-07'),
('DB2 Bob', 22, 'B', 'db2.bob@example.com', '2025-02-10'),
('DB2 Charlie', 21, 'A', 'db2.charlie@example.com', '2025-03-02'),
('DB2 David', 23, 'C', 'db2.david@example.com', '2025-03-06'),
('DB2 Eva', 20, 'B', 'db2.eva@example.com', '2025-03-07');
execute sql script
Menu Refresh
Now, You can see :
DB2INST1
STUDENTS
Select the table: STUDENTS
Menu: View Table
select tab: Data
select ER Diagram
docker ps
get DB2 Container Name: docker_db2_db2_1
docker exec -it docker_db2_db2_1 bash
In Container
su - db2inst1
dbtest
db2 force applications all
db2 drop database dbtest
dbtest
and include the Sample table and data.db2sampl -dbpath /database/data -name dbtest -sql -force -verbose
wait until finish
Creating database "dbtest" on path "/database/data"...
Existing "dbtest" database found...
Dropping and recreating database "dbtest"...
Connecting to database "dbtest"...
Creating tables and data in schema "DB2INST1"...
'db2sampl' processing complete.
DBTEST With Sample Table and Data