GAGA LIFE.

DBAブログ

Docker上にOracle Database 12.2を構築

概要

Docker(CentOS)にOracle Database EE 12.2.0.1をインストールします。

環境情報

ホストOS:Windows 10
VirtualBox:Ver 5.2.8
ゲストOS:CentOS 7 64bit
Oracle:Oracle Database EE 12.2.0.1

手順概要

基本的に以下の公式の手順とスクリプトを使用して構築しています。

https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/README.md

1.Dockerイメージの準備(配置)
2.buildDockerImage.shの動作確認
3.インストールモジュール準備
4.データベース環境作成
5.データベース作成
6.インスタンスへの接続確認

手順説明

1.Dockerイメージの準備

https://github.com/oracle/docker-images
[Clone or download]ボタンを押してダウンロードしました。
※「docker-images/OracleDatabase/SingleInstance/dockerfiles」配下がデータベース用

2.buildDockerImage.shの動作確認

今回は、「/home/oracle」配下でダウンロードした「docker-images-master.zip」を解凍して実行しました。

/home/oracle/docker-images-master/OracleDatabase/SingleInstance/dockerfiles配下に「buildDockerImage.sh」が展開されます。hオプション(help)で実行確認します。

3.インストールモジュールの準備

下記OTNサイトから(ライセンスに同意し)ダウンロード

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/oracle12c-linux-12201-3608234.html?ssSourceSiteId=otnjp
ダウンロードファイル名:linuxx64_12201_database

ダウンロードしたファイルは、解凍せず(zip形式のまま)に以下のディレクトリ配下へ格納しています。
docker-images/OracleDatabase/dockerfiles/12.2.0.1

4.データベース環境作成

ファイルの配置とパーミッション等が整備されていれば、シェルスクリプトを実行するのみです。それぞれの引数の意味はhelpから確認可能です。

$ ./buildDockerImage.sh -h
Usage: buildDockerImage.sh -v [version] [-e | -s | -x] [-i] [-o] [Docker build option]
Builds a Docker Image for Oracle Database.
Parameters:
-v: version to build
Choose one of: 11.2.0.2 12.1.0.2 12.2.0.1
-e: creates image based on 'Enterprise Edition'
-s: creates image based on 'Standard Edition 2'
-x: creates image based on 'Express Edition'
-i: ignores the MD5 checksums
-o: passes on Docker build option
* select one edition only: -e, -s, or -x
5.データベースの作成

以下の構成で作成しています。

・MTA(マルチテナントアーキテクチャ)
    --> CDB(コンテナ)+1PDB(プラガブル)

・環境変数(コンテナ/プラガブル)
ORACLE_SID=orcl
ORACLE_PDB=pdb1

・ポート構成
DBへの接続ポート:1521
EMへの接続ポート:5500

・データのDockerホストへのマッピング先
/mnt/oradata

・管理者ユーザパスワード
起動(docker run実行)後、以下の文字列後に出力されます。今回の例では、「uD/aDlgT6YY=1」(手順内の赤字部分)となります。

ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN:

手順実行

1.Dockerイメージの準備(配置)
[oracle@Marshall dockerfiles]$ pwd
/home/oracle/docker-images-master/OracleDatabase/SingleInstance/dockerfiles
[oracle@Marshall dockerfiles]$ ll
合計 12
drwxrwxr-x 2 oracle oracle 126 5月 4 05:45 11.2.0.2
drwxrwxr-x 2 oracle oracle 4096 5月 4 05:45 12.1.0.2
drwxrwxr-x 2 oracle oracle 4096 5月 4 15:15 12.2.0.1
-rwxr-xr-x 1 oracle oracle 4093 5月 4 05:45 buildDockerImage.sh
 2.buildDockerImage.shの動作確認
[oracle@Marshall dockerfiles]$ ./buildDockerImage.sh -h
Usage: buildDockerImage.sh -v [version] [-e | -s | -x] [-i] [-o] [Docker build option]
Builds a Docker Image for Oracle Database.

Parameters:
-v: version to build
Choose one of: 11.2.0.2 12.1.0.2 12.2.0.1
-e: creates image based on 'Enterprise Edition'
-s: creates image based on 'Standard Edition 2'
-x: creates image based on 'Express Edition'
-i: ignores the MD5 checksums
-o: passes on Docker build option
* select one edition only: -e, -s, or -x
LICENSE UPL 1.0
Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.
 3.インストールモジュール準備
[oracle@Marshall dockerfiles]$ ls -la 12.2.0.1/
合計 3372832
drwxrwxr-x 2 oracle oracle 4096 5月 4 15:15 .
drwxrwxr-x 5 oracle oracle 81 5月 4 15:15 ..
-rw-rw-r-- 1 oracle oracle 62 5月 4 05:45 Checksum.ee
-rw-rw-r-- 1 oracle oracle 62 5月 4 05:45 Checksum.se2
-rw-rw-r-- 1 oracle oracle 2639 5月 4 05:45 Dockerfile.ee
-rw-rw-r-- 1 oracle oracle 2645 5月 4 05:45 Dockerfile.se2
-rwxr-xr-x 1 oracle oracle 1148 5月 4 05:45 checkDBStatus.sh
-rwxr-xr-x 1 oracle oracle 905 5月 4 05:45 checkSpace.sh
-rwxr-xr-x 1 oracle oracle 2953 5月 4 05:45 createDB.sh
-rw-rw-r-- 1 oracle oracle 6878 5月 4 05:45 db_inst.rsp
-rw-rw-r-- 1 oracle oracle 9203 5月 4 05:45 dbca.rsp.tmpl
-rwxr-xr-x 1 oracle oracle 2250 5月 4 05:45 installDBBinaries.sh
-rwxrwxrwx 1 oracle oracle 3453696911 5月 4 15:08 linuxx64_12201_database.zip
-rwxr-xr-x 1 oracle oracle 6140 5月 4 05:45 runOracle.sh
-rwxr-xr-x 1 oracle oracle 1015 5月 4 05:45 runUserScripts.sh
-rwxr-xr-x 1 oracle oracle 758 5月 4 05:45 setPassword.sh
-rwxr-xr-x 1 oracle oracle 876 5月 4 05:45 setupLinuxEnv.sh
-rwxr-xr-x 1 oracle oracle 678 5月 4 05:45 startDB.sh
 4.データベース環境作成(事前にoracleユーザーをdockerグループに所属させる)
[oracle@Marshall dockerfiles]$ sudo usermod -g docker oracle
[oracle@Marshall dockerfiles]$ sudo /bin/systemctl restart docker.service
[oracle@Marshall dockerfiles]$ chmod -R 777 12.2.0.1/
[oracle@Marshall dockerfiles]$ ./buildDockerImage.sh -v 12.2.0.1 -e
Checking if required packages are present and valid...
linuxx64_12201_database.zip: 完了
==========================
DOCKER info:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 18.03.1-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.21.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.639GiB
Name: Marshall
ID: Q4LG:MHDV:WLFM:ESFU:J2LR:DVMU:5XML:MXRP:XDJH:RNN2:F7Q3:ZH4A
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
==========================
Building image 'oracle/database:12.2.0.1-ee' ...
Sending build context to Docker daemon 557.1kB
Sending build context to Docker daemon 16.71MB
~(略)~
Step 17/17 : CMD exec $ORACLE_BASE/$RUN_FILE
---> Running in af5dccf2c8df
Removing intermediate container af5dccf2c8df
---> e7f871e54a42
Successfully built e7f871e54a42
Successfully tagged oracle/database:12.2.0.1-ee
Oracle Database Docker Image for 'ee' version 12.2.0.1 is ready to be extended:

--> oracle/database:12.2.0.1-ee
Build completed in 1199 seconds.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/database 12.2.0.1-ee e7f871e54a42 5 minutes ago 13.2GB
oraclelinux 7-slim c94cc930790a 2 weeks ago 117MB
hello-world latest e38bc07ac18e 3 weeks ago 1.85kB
 5.データベース作成
[oracle@Marshall dockerfiles]$ sudo mkdir -p /mnt/oradata
[sudo] oracle のパスワード:
[oracle@Marshall dockerfiles]$ sudo chmod -R 777 /mnt/
$ docker run --name orcl -p 1521:1521 -p 5500:5500 -v /mnt/oradata:/opt/oracle/oradata -e ORACLE_SID=orcl -e ORACLE_PDB=pdb1 \
oracle/database:12.2.0.1-ee
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: uD/aDlgT6YY=1
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 04-MAY-2018 07:20:51
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Starting /opt/oracle/product/12.2.0.1/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/1a8fca70b910/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 04-MAY-2018 07:20:51
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/1a8fca70b910/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully
[WARNING] [DBT-10102] The listener configuration is not selected for the database. EM DB Express URL will not be accessible.
CAUSE: The database should be registered with a listener in order to access the EM DB Express URL.
ACTION: Select a listener to be registered or created with the database.
Copying database files
1% complete
13% complete
25% complete
Creating and starting Oracle instance
26% complete
30% complete
31% complete
35% complete
38% complete
39% complete
41% complete
Completing Database Creation
42% complete
43% complete
44% complete
46% complete
47% complete
50% complete
Creating Pluggable Databases
55% complete
75% complete
Executing Post Configuration Actions
100% complete
Look at the log file "/opt/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
SQL*Plus: Release 12.2.0.1.0 Production on Fri May 4 07:27:42 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL>
System altered.
 
~(略)~
 
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
PDB1(3):Undo initialization finished serial:0 start:12400018 end:12400074 diff:56 ms (0.1 seconds)
PDB1(3):Database Characterset for PDB1 is AL32UTF8
PDB1(3):Opatch validation is skipped for PDB PDB1 (con_id=0)
PDB1(3):Opening pdb with no Resource Manager plan active
Pluggable database PDB1 opened read write
 
~(略)~
 
6.インスタンスへの接続確認
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aaeca05e3663 oracle/database:12.2.0.1-ee "/bin/sh -c 'exec $O…" About a minute ago Up About a minute (healthy) 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp orcl
4657c933c926 hello-world "/hello" 32 hours ago Exited (0) 32 hours ago laughing_engelbart
[oracle@Marshall oradata]$ docker exec -it orcl /bin/bash
[oracle@aaeca05e3663 ~]$ sqlplus /nolog
SQL*Plus: Release 12.2.0.1.0 Production on Fri May 4 08:57:24 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl OPEN
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO

▽Enterprise Managerへのアクセス

Dockerホスト側から以下でEMへのアクセスも可能
https://localhost:5500/em/

参考資料

https://github.com/oracle/docker-images