Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to DB2 running on docker

I have installed the image ibmcom/db2 on docker running on local Docker Desktop on Windows 10.

Following this guide to setup:
https://www.ibm.com/docs/en/db2/11.5?topic=system-windows

I am able to query the sample DB from the db2 command prompt, as described here:
https://www.ibm.com/docs/en/db2/11.5?topic=windows-testing-your-db2-community-edition-docker-image-installation-systems

The parameters in the .end_list config file were:

LICENSE=accept  
DB2INSTANCE=db2inst1  
DB2INST1_PASSWORD=password  
DBNAME=testdb  
BLU=false  
ENABLE_ORACLE_COMPATIBILITY=false  
UPDATEAVAIL=NO  
TO_CREATE_SAMPLEDB=false  
REPODB=false  
IS_OSXFS=false  
PERSISTENT_HOME=false  
HADR_ENABLED=false  
ETCD_ENDPOINT=  
ETCD_USERNAME=  
ETCD_PASSWORD=  

I started the server using this command:

docker run -h db2server --name db2server --restart=always --detach --privileged=true -p  50000:50000 --env-file .env_list -v C:/Kode/Docker/db2:/database ibmcom/db2

This is fine. But I need to connect from DBeaver.

I have tried these parameters:

Host: localhost / db2server
Port: 50000
Database: sample
Username: db2admin
Password: db2admin / DB2INST1_PASSWORD from config file

With "localhost" as host, it fails immediately with the following message: [jcc][t4][2013][11249][4.26.14] Connection authorization failure occurred.
Reason: User ID or Password invalid. ERRORCODE=-4214, SQLSTATE=28000

With "db2server" as host it takes a bit longer, then it fails with the following message: [jcc][t4][10380][11951][4.26.14] Required property "db2server" is unknown host. ERRORCODE=-4222, SQLSTATE=08001

So, I am guessing that using the name of the server/container on docker as hostname is not working at all, since it seems that the name cannot be resolved.

Using localhost seems to work a little bit better, as it seems the error message is coming from the server, but I don't see what username/password I should use when the ones I know are rejected.

DBeaver seems to be using jdbc.

So the question is: how can I connect to db2 on docker (same machine) from DBeaver? Any suggestions will be apreciated!

like image 378
Svein Terje Gaup Avatar asked Oct 17 '25 17:10

Svein Terje Gaup


1 Answers

The first time the setup of the xdb2 container will take a few minutes. That won't happen the second time an on. Run:

docker run -itd --name xdb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=pass1 -e DBNAME=testdb -v /home/user1/volumes/db2:/database ibmcom/db2:11.5.7.0

where /home/user1/volumes/db2 is the local directory where the data will be persisted.

Then, check the container started normally with:

docker logs -f xdb2

At some point (takes a bit) it shows: Setup has completed.

To stop the container run:

docker stop xdb2

To start the container run:

docker start xdb2

To connect using JDBC:

  • URL: jdbc:db2://192.168.56.220:50000/testdb:currentSchema=SCHEMA1;
  • user: db2inst1
  • pass: <password-of-the-os-user>

Above 192.168.56.220 is the host/IP where the docker server is running.

like image 175
The Impaler Avatar answered Oct 20 '25 10:10

The Impaler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!