docker pull ibmcom/db2 

docker run -itd --name db2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=Docker_db2_50000 -e DBNAME=simple -v /dp/docker/data/db2:/database ibmcom/db2

登录容器
docker exec -it db2 bash

切换到实例用户db2inst1

su - db2inst1

启动实例

db2start

查看运行状态

db2pd -

查看数据库和补丁版本

db2level


查看已经创建的数据库

db2 list db directory



连接数据库

db2 connect to simple

如果提示异常:
SQL1035N  The operation failed because the specified database cannot be 
connected to in the mode requested.  SQLSTATE=57019

是因为前滚到日志末尾后停止

先执行

db2 rollforward db simple to end of logs and stop
再连接


执行SQL 注意不支持回车换行

 db2 "create table TEST1(ID BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1,INCREMENT BY 1),USER_NAME VARCHAR(20),USER_AGES INT)"

 db2 "select * from test1"


DBeaver连接 选DB2中的DB2 LUW

帐号:db2inst1
密码:Docker_db2_50000

JDBC操作参考