Skip to content

Commit b45e95b

Browse files
lerochaclaude
andcommitted
Add DB2 auto-initialization support
Implemented auto-initialization for DB2 container using inline bash command: - Added healthcheck to ensure DB2 database is ready before running init script - Auto-loads Chinook database with all tables and data on startup - Uses inline command in docker-compose.yml (no external script files needed) - Cleaned up environment variables and fixed BLU syntax error Database initialization verified with 275 artists loaded across 11 tables. Note: DB2 .NET tests cannot run on macOS ARM64 due to IBM.Data.DB2.Core library limitations, but the database container itself works correctly and can be tested via docker exec. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a271523 commit b45e95b

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

‎docker-compose.yml‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,36 @@ services:
1414
image: icr.io/db2_community/db2:latest
1515
platform: linux/amd64
1616
privileged: true
17-
restart: always
1817
environment:
1918
LICENSE: accept
2019
DB2INSTANCE: chinook
2120
DB2INST1_PASSWORD: chinook
2221
DBNAME: Chinook
23-
BLU=: false
22+
BLU: false
2423
ENABLE_ORACLE_COMPATIBILITY: false
2524
UPDATEAVAIL: NO
2625
TO_CREATE_SAMPLEDB: false
2726
REPODB: false
28-
IS_OSXFS: true # identifies the operating system as macOS
29-
PERSISTENT_HOME: true # true by default and should only specified as false when running Docker for Windows
27+
IS_OSXFS: true
28+
PERSISTENT_HOME: false
3029
HADR_ENABLED: false
31-
ETCD_ENDPOINT:
32-
ETCD_USERNAME:
33-
ETCD_PASSWORD:
3430
ports:
3531
- "50000:50000"
3632
volumes:
37-
- ./ChinookDatabase/DataSources/Chinook_Db2.sql:/docker-entrypoint-initdb.d/create_database.sql
38-
# Note: DB2 does not auto-run scripts. Manual initialization required:
39-
# docker exec chinook-db2-1 su - chinook -c "db2 connect to Chinook && db2 -tf /docker-entrypoint-initdb.d/create_database.sql"
33+
- ./ChinookDatabase/DataSources/Chinook_Db2.sql:/scripts/Chinook_Db2.sql
34+
healthcheck:
35+
test: ["CMD", "su", "-", "chinook", "-c", "db2 connect to Chinook"]
36+
interval: 10s
37+
timeout: 5s
38+
retries: 60
39+
start_period: 120s
40+
command: >
41+
bash -c '
42+
/var/db2_setup/lib/setup_db2_instance.sh &
43+
until su - chinook -c "db2 connect to Chinook" > /dev/null 2>&1; do sleep 5; done;
44+
su - chinook -c "db2 connect to Chinook && db2 -tf /scripts/Chinook_Db2.sql";
45+
tail -f /dev/null
46+
'
4047
4148
#----------------------------------------------------------------------------
4249
# MySQL Container

0 commit comments

Comments
 (0)