Docker Store から Oracle Database 構築

Docker Store から Oracle Database 構築
===
Oracle Database 動作確認のための環境構築（データ永続化などは省略）。
Docker Store から初めてイメージ取得するので、備忘録として。

#### 構築環境（Docker for Windows）

| OS | x86-x64 | Memory |
| :--------: | :--------: | :--------: |
| Microsoft Windows 10 Pro | x64 | 4GB |

---

## 1. Docker Store から情報入手

Docker Store にアクセス。
https://store.docker.com/

Oracle と検索し、「Oracle Database Enterprise Edition」を選択。
![](https://i.imgur.com/qomMQSC.png)

手順省略（画面コピーとってなかった...）するが、

* Docker にログイン <font color=red>※アカウント登録が必要</font>
* 画面右にある "Get Contents" をクリック
* 必要事項を入力し、再度 "Get Contents" をクリック

セットアップ手順（英文）が表示されるので、基本的にはこれを参考に構築。
<font color=green>※下図赤枠右のアイコンクリックで、docker pull コマンドをコピー可能</font>
![](https://i.imgur.com/N5gTSyA.png)

---

<font color=red>※以下は作業メモ。</font>

## 2. Docker で環境構築

### 2-1. Docker Image のダウンロード

コマンドプロンプトを起動。
Docker Store からダウンロードするために、Docker Hub にログイン。

```
> docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username:
Password:
Login Succeeded
```

Docker Store に表示されていたコマンドを実行し、Docker イメージをダウンロード。

```
# Docker Store から Docker イメージをダウンロード
> docker pull store/oracle/database-enterprise:12.2.0.1
12.2.0.1: Pulling from store/oracle/database-enterprise
: Pull complete
: Pull complete
: Pull complete
: Pull complete
: Pull complete
Digest: 
Status: Downloaded newer image for store/oracle/database-enterprise:12.2.0.1
# Docker Hub にログインしていない状態で実行すると、タイムアウトでダウンロード失敗
# Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

# ダウンロードした Docker イメージを確認（3.44GBある）
> docker image ls
REPOSITORY                         TAG        IMAGE ID       CREATED         SIZE
store/oracle/database-enterprise   12.2.0.1   12a359cd0528   11 months ago   3.44GB
```

Docker Hub からログアウト。

```
> docker logout
Removing login credentials for https://index.docker.io/v1/
```

---

### 2-2. コンテナ起動

docker コンテナを起動。

```
> docker run -d -it --name <Oracle-DB> store/oracle/database-enterprise:12.2.0.1
2540dabea1323b3a9387e545c3e66a8ce5e90fa56c1b3fb7b5c467d46e5b97dd

> docker ps
CONTAINER ID   IMAGE                                       COMMAND                   CREATED         STATUS                            PORTS                NAMES
2540dabea132   store/oracle/database-enterprise:12.2.0.1   "/bin/sh -c '/bin/ba…"   6 seconds ago   Up 4 seconds (health: starting)   1521/tcp, 5500/tcp   <Oracle-DB>
```

---

## 3. DataBase へのアクセス

下表の作成済みユーザを使用して操作。　<font color=red>※パスワード変更を推奨</font>

| UserID | PassWord |
| :--------: | :--------: |
| sys | Oradoc_db1 |

```
# コンテナ内に入る
> docker exec -it <Oracle-DB> bash

# 公開されている sys ユーザで SQL*Plus 接続可能
$ sqlplus sys/Oradoc_db1@ORCLCDB as sysdba
```

---

## その他

RMANも実行可能。

```
$ rman target /

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Jul 31 09:44:23 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCLCDB (DBID=2722566360)

# 設定は全てデフォルトの状態 #######################################################
RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCLCDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.2.0/dbhome_1/dbs/snapcf_ORCLCDB.f'; # default

# アーカイブモード無効のため、ホットバックアップは不可（エラー発生） ##################
RMAN> backup database;

Starting backup at 31-JUL-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=47 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 07/31/2018 09:46:33
RMAN-06149: cannot BACKUP DATABASE in NOARCHIVELOG mode

# コールドバックアップの実行 #######################################################
# 1. Oracle インスタンスのシャットダウン
RMAN> shutdown immediate;

database closed
database dismounted
Oracle instance shut down

# 2. データベースのマウント
RMAN> startup mount;

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area    1342177280 bytes

Fixed Size                     8792536 bytes
Variable Size                369100328 bytes
Database Buffers             956301312 bytes
Redo Buffers                   7983104 bytes

# 3. バックアップの実行
RMAN> backup database;

Starting backup at 24-AUG-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=237 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u02/app/oracle/oradata/ORCL/system01.dbf
input datafile file number=00003 name=/u02/app/oracle/oradata/ORCL/sysaux01.dbf
input datafile file number=00012 name=/u02/app/oracle/oradata/ORCL/undotbs01.dbf
input datafile file number=00007 name=/u02/app/oracle/oradata/ORCL/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-AUG-18
channel ORA_DISK_1: finished piece 1 at 24-AUG-18
piece handle=/u03/app/oracle/fast_recovery_area/ORCLCDB/backupset/2018_08_24/o1_mf_nnndf_TAG20180824T071855_fqzdc0jx_.bkp tag=TAG20180824T071855 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00018 name=/u02/app/oracle/oradata/ORCLCDB/orclpdb1/sysaux01.dbf
input datafile file number=00017 name=/u02/app/oracle/oradata/ORCLCDB/orclpdb1/system01.dbf
input datafile file number=00019 name=/u02/app/oracle/oradata/ORCLCDB/orclpdb1/undotbs01.dbf
input datafile file number=00020 name=/u02/app/oracle/oradata/ORCLCDB/orclpdb1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-AUG-18
channel ORA_DISK_1: finished piece 1 at 24-AUG-18
piece handle=/u03/app/oracle/fast_recovery_area/ORCLCDB/7248190FCB870138E053020011AC5826/backupset/2018_08_24/o1_mf_nnndf_TAG20180824T071855_fqzdchxv_.bkp tag=TAG20180824T071855 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u02/app/oracle/oradata/ORCL/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/u02/app/oracle/oradata/ORCL/pdbseed/system01.dbf
input datafile file number=00008 name=/u02/app/oracle/oradata/ORCL/pdbseed/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 24-AUG-18
channel ORA_DISK_1: finished piece 1 at 24-AUG-18
piece handle=/u03/app/oracle/fast_recovery_area/ORCLCDB/49BBBDA685E81921E053AA43C40A7BEA/backupset/2018_08_24/o1_mf_nnndf_TAG20180824T071855_fqzdcz7q_.bkp tag=TAG20180824T071855 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 24-AUG-18

Starting Control File and SPFILE Autobackup at 24-AUG-18
piece handle=/u03/app/oracle/fast_recovery_area/ORCLCDB/autobackup/2018_08_24/o1_mf_s_984986270_fqzddh77_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 24-AUG-18

# 4. データベースのオープン
RMAN> alter database open;

Statement processed
```

---

## 参照URL

Oracle Database(CDB) on Docker を動かしてみる（2017/11/17 JPOUG in 15 minutes）
https://www.slideshare.net/oracle4engineer/oracle-database-cdb-on-docker

docker storeに公開されている公式Oracle Enterprise Editionを動かしてみる
https://blog.intracker.net/archives/1130