DB2 Docker 起動手順書

# Docker 利用イメージ

https://hub.docker.com/r/ibmcom/db2

## イメージ取得

```console
$ docker pull ibmcom/db2
```

## 設定ファイル編集

`db2.env` というファイルを作成。

```console
$ cat db2.env
# set License to accept to use the Db2 software contained in this image
LICENSE=accept
# specify the Db2 Instance name
DB2INSTANCE=db2inst1
# specify the Db2 Instance password
DB2INST1_PASSWORD=hogehoge
# create an initial database with the name provided or leave empty
DBNAME=testdb
# set to true to enable BLU on instance
BLU=false
# set to true to enable Oracle Compatibility on instance
ENABLE_ORACLE_COMPATIBILITY=true
# set to true to create sample database
SAMPLEDB=true
```

## コンテナ起動

```console
$ docker run -itd --name mydb2 --privileged=true -p 50000:50000 -e LICENSE=accept --env-file ./db2.env ibmcom/db2
```

## 起動確認

`docker run` コマンド実行後、セットアップまで時間がかかる。
ログを確認し、`Setup has completed.`  というメッセージが表示されるまで待つ。

```console
$ docker logs -f mydb2

...省略...
(*) Setup has completed.
...省略...
```

## コンテナログイン

```console
$ docker exec -ti mydb2 bash -c "su - db2inst1"
```

### DB 接続

```console
$ db2 connect to sample

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.0.0
 SQL authorization ID   = DB2INST1
 Local database alias   = SAMPLE
```

### テーブル一覧表示

```console
$ db2 list tables

Table/View                      Schema          Type  Creation time
------------------------------- --------------- ----- --------------------------
ACT                             DB2INST1        T     2020-01-30-07.36.19.158807
ADEFUSR                         DB2INST1        S     2020-01-30-07.36.20.996509
CATALOG                         DB2INST1        T     2020-01-30-07.36.24.475091
CL_SCHED                        DB2INST1        T     2020-01-30-07.36.18.357790
CUSTOMER                        DB2INST1        T     2020-01-30-07.36.24.085459
DEPARTMENT                      DB2INST1        T     2020-01-30-07.36.18.411644
DEPT                            DB2INST1        A     2020-01-30-07.36.18.515551
EMP                             DB2INST1        A     2020-01-30-07.36.18.601871
EMPACT                          DB2INST1        A     2020-01-30-07.36.19.153333
EMPLOYEE                        DB2INST1        T     2020-01-30-07.36.18.516421
EMPMDC                          DB2INST1        T     2020-01-30-07.36.21.240795
EMPPROJACT                      DB2INST1        T     2020-01-30-07.36.19.100002
EMP_ACT                         DB2INST1        A     2020-01-30-07.36.19.155021
EMP_PHOTO                       DB2INST1        T     2020-01-30-07.36.18.602608
EMP_RESUME                      DB2INST1        T     2020-01-30-07.36.18.747302
INVENTORY                       DB2INST1        T     2020-01-30-07.36.23.981677
IN_TRAY                         DB2INST1        T     2020-01-30-07.36.19.333151
ORG                             DB2INST1        T     2020-01-30-07.36.19.403872
PRODUCT                         DB2INST1        T     2020-01-30-07.36.23.794566
PRODUCTSUPPLIER                 DB2INST1        T     2020-01-30-07.36.25.163089
PROJ                            DB2INST1        A     2020-01-30-07.36.18.983616
PROJACT                         DB2INST1        T     2020-01-30-07.36.18.984442
PROJECT                         DB2INST1        T     2020-01-30-07.36.18.897834
PURCHASEORDER                   DB2INST1        T     2020-01-30-07.36.24.198564
SALES                           DB2INST1        T     2020-01-30-07.36.19.567489
STAFF                           DB2INST1        T     2020-01-30-07.36.19.508617
STAFFG                          DB2INST1        T     2020-01-30-07.36.20.735949
SUPPLIERS                       DB2INST1        T     2020-01-30-07.36.24.756518
VACT                            DB2INST1        V     2020-01-30-07.36.19.673338
VASTRDE1                        DB2INST1        V     2020-01-30-07.36.19.732414
VASTRDE2                        DB2INST1        V     2020-01-30-07.36.19.738845
VDEPMG1                         DB2INST1        V     2020-01-30-07.36.19.704552
VDEPT                           DB2INST1        V     2020-01-30-07.36.19.646021
VEMP                            DB2INST1        V     2020-01-30-07.36.19.665735
VEMPDPT1                        DB2INST1        V     2020-01-30-07.36.19.722951
VEMPLP                          DB2INST1        V     2020-01-30-07.36.19.774610
VEMPPROJACT                     DB2INST1        V     2020-01-30-07.36.19.699081
VFORPLA                         DB2INST1        V     2020-01-30-07.36.19.758732
VHDEPT                          DB2INST1        V     2020-01-30-07.36.19.661254
VPHONE                          DB2INST1        V     2020-01-30-07.36.19.770769
VPROJ                           DB2INST1        V     2020-01-30-07.36.19.668506
VPROJACT                        DB2INST1        V     2020-01-30-07.36.19.676860
VPROJRE1                        DB2INST1        V     2020-01-30-07.36.19.744898
VPSTRDE1                        DB2INST1        V     2020-01-30-07.36.19.750844
VPSTRDE2                        DB2INST1        V     2020-01-30-07.36.19.755270
VSTAFAC1                        DB2INST1        V     2020-01-30-07.36.19.762477
VSTAFAC2                        DB2INST1        V     2020-01-30-07.36.19.766166

  47 record(s) selected.
```