skip to Main Content

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!

2

Answers


  1. As authentication (checking userid and password) happens inside the container (i.e not using the Win10 on the host), you must use a userid:password combibation that is already created inside the container, for example db2inst1 as per your env file.

    You must also reference the database name that is created on the container (e.g. testdb as per your env file). You cannot use username db2admin until and unless you create that account inside the container.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search