环境
一个Docker Hub账号。一台Linux 主机。
目标
操作系统Oracle Linux 7,运行容器数据库,数据库为单实例企业版,版本12.2.0.1,实例名为ORCLCDB,带一个可插拔数据库orclpdb1。
创建Linux操作系统
如果用本地的Windows笔记本,在Vagrantfile中将内存改为4096,然后创建虚机(Oracle Linux 7)。耗时6分59秒。
PS E:\DB\vagrant-boxes\OracleLinux\7> Measure-Command { vagrant up | Out-Default}
本例我使用的是OCI公有云上的主机,因为下载快些。
安装Docker
安装Docker,耗时1m9.076s:
sudo yum install -y yum-utils
sudo yum-config-manager --enable ol7_addons
sudo yum install -y docker-engine
sudo systemctl start docker
sudo systemctl enable docker
确认:
$ sudo docker version
Client: Docker Engine - Community
Version: 18.09.8-ol
API version: 1.39
Go version: go1.10.8
Git commit: 76804b7
Built: Fri Sep 27 21:00:18 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.8-ol
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 76804b7
Built: Fri Sep 27 20:54:00 2019
OS/Arch: linux/amd64
Experimental: false
Default Registry: docker.io
用户vagrant加入到docker组,如果是OCI公有云,改为opc用户:
$ sudo usermod -aG docker vagrant
$ id vagrant
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),10(wheel),993(docker)
Pull Docker Image
访问Docker Hub中Oracle专属页面。
$ docker login
$ docker pull store/oracle/database-enterprise:12.2.0.1 或者
$ docker pull store/oracle/database-enterprise:12.2.0.1-slim
非slim版3.44GB,耗时5m38.318s(另一次仅用了2分钟);slim版小一些,为2.08GB,耗时2m51.174s。
slim版没有以下功能:
Analytics, Oracle R, Oracle Label Security, Oracle Text, Oracle Application Express and Oracle DataVault
查看image:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
store/oracle/database-enterprise 12.2.0.1 12a359cd0528 2 years ago 3.44GB
store/oracle/database-enterprise 12.2.0.1-slim 27c9559d36ec 2 years ago 2.08GB
创建容器数据库
docker run -d -it --name odbee12201 -P store/oracle/database-enterprise:12.2.0.1
数据库就绪还需要一些时间,请观察日志,等待信息Done ! The database is ready for use .
出现,此步骤用了190秒:
[opc@instance-20191112-1400-docker ~]$ docker logs -f e406b9ec748b
Setup Oracle Database
Oracle Database 12.2.0.1 Setup
Wed Nov 20 07:22:50 UTC 2019
Check parameters ......
log file is : /home/oracle/setup/log/paramChk.log
paramChk.sh is done at 0 sec
untar DB bits ......
log file is : /home/oracle/setup/log/untarDB.log
untarDB.sh is done at 128 sec
config DB ......
log file is : /home/oracle/setup/log/configDB.log
Wed Nov 20 07:24:58 UTC 2019
Start Docker DB configuration
Call configDBora.sh to configure database
Wed Nov 20 07:24:58 UTC 2019
Configure DB as oracle user
Setup Database directories ...
SQL*Plus: Release 12.2.0.1.0 Production on Wed Nov 20 07:24:58 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
SQL>
File created.
SQL> ORACLE instance started.
Total System Global Area 1342177280 bytes
Fixed Size 8792536 bytes
Variable Size 352323112 bytes
Database Buffers 973078528 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.
SQL>
Database altered.
SQL>
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u01/app/oracle/product/12.2.0
/dbhome_1/dbs/spfileORCLCDB.or
a
SQL>
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
encrypt_new_tablespaces string CLOUD_ONLY
SQL>
User altered.
SQL>
User altered.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
update password
Enter password for SYS:
create pdb : ORCLPDB1
SQL*Plus: Release 12.2.0.1.0 Production on Wed Nov 20 07:25:22 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> 2 3 4 5
Pluggable database created.
SQL>
Pluggable database altered.
SQL>
Pluggable database altered.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Reset Database parameters
SQL*Plus: Release 12.2.0.1.0 Production on Wed Nov 20 07:25:59 2019
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.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 20-NOV-2019 07:26:00
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Starting /u01/app/oracle/product/12.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0/dbhome_1/admin/ORCLCDB/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/e406b9ec748b/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 20-NOV-2019 07:26:00
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0/dbhome_1/admin/ORCLCDB/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/e406b9ec748b/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
DONE!
Remove password info
Docker DB configuration is complete !
configDB.sh is done at 190 sec
Done ! The database is ready for use .
# ===========================================================================
# == Add below entries to your tnsnames.ora to access this database server ==
# ====================== from external host =================================
ORCLCDB=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<ip-address>)(PORT=<port>))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCLCDB.localdomain)))
ORCLPDB1=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<ip-address>)(PORT=<port>))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCLPDB1.localdomain)))
#
#ip-address : IP address of the host where the container is running.
#port : Host Port that is mapped to the port 1521 of the container.
#
# The mapped port can be obtained from running "docker port <container-id>"
# ===========================================================================
Thread 1 advanced to log sequence 5 (LGWR switch)
Current log# 2 seq# 5 mem# 0: /u04/app/oracle/redo/redo002.log
2019-11-20T07:25:59.417368+00:00
ORCLPDB1(3):Opening pdb with no Resource Manager plan active
Pluggable database ORCLPDB1 opened read write
Completed: alter pluggable database ORCLPDB1 open
alter pluggable database all save state
Completed: alter pluggable database all save state
2019-11-20T07:26:00.020580+00:00
ALTER SYSTEM SET encrypt_new_tablespaces='DDL' SCOPE=BOTH;
2019-11-20T07:26:18.171083+00:00
TABLE SYS.WRP$_REPORTS: ADDED INTERVAL PARTITION SYS_P287 (3611) VALUES LESS THAN (TO_DATE(' 2019-11-21 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLE SYS.WRP$_REPORTS_DETAILS: ADDED INTERVAL PARTITION SYS_P288 (3611) VALUES LESS THAN (TO_DATE(' 2019-11-21 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
2019-11-20T07:26:18.275624+00:00
Shared IO Pool defaulting to 64MB. Trying to get it from Buffer Cache for process 511.
TABLE SYS.WRP$_REPORTS_TIME_BANDS: ADDED INTERVAL PARTITION SYS_P291 (3610) VALUES LESS THAN (TO_DATE(' 2019-11-20 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
登录容器:
docker exec -it odbee12201 bash
直接登录数据库:
$ docker exec -it odbee12201 bash -c "source /home/oracle/.bashrc; sqlplus / as sysdba"
数据库版本为12.2.0.1,实例名为ORCLCDB,带一个可插拔数据库orclpdb1。
参考
- https://hub.docker.com/publishers/oracle
- https://hub.docker.com/_/oracle-database-enterprise-edition
- https://www.oracle.com/technical-resources/articles/cloud/deploy-database-in-container-cloud.html
- https://blogs.oracle.com/imc/partner-webcast-oracle-database-running-on-docker-in-oracle-container-cloud-service