Oracle 已经宣布支持了Docker部署,这也让我们在Mac上部署 Oracle 数据库有了多一个选择,这是我的第一个Docker应用,非常简便快速的就完成了部署,简捷是最直接的体验。在 云和恩墨 恩墨学院 的培训中,我们使用Docker为环境部署实现了极大的便利和简化。

首先要做的是准备工作,备好需要的软件,安装Docker环境,这些极其简单。

下载一个Docker的稳定版本,『Docker Community Edition for Mac』即可:

以下链接:

https://store.docker.com/editions/community/docker-ce-desktop-mac

选择稳定版本:

https://download.docker.com/mac/stable/Docker.dmg

这也是我第一次安装Docker,看着熟悉的小鲸鱼游进文件夹,第一步的准备工作基本就做好了:

DockerInstall.jpg

接下来还需要在Github上下载Oracle的Docker Image文件(下载之后的文件是 docker-images-master.zip ):

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

OracleOnGitHub.jpg

此外,你还需要最新的Oracle 12.2 数据库安装包,可以从OTN下载(安装文件是 linuxx64_12201_database.zip):

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

在成功安装了Docker之后,就可以部署Oracle数据库了

在Docker中部署Oracle数据库,简化到只需要一个核心命令。

我将整个过程概括为3个环节:

第一步:准备安装程序

主要是 docker-images-master.zip 和 linuxx64_12201_database.zip ,解压Docker的主体文件,然后将Oracle的安装文件加入到OracleDatabase/dockerfiles的相应目录下,准备工作就就绪了。

准备工作基本上就两条命令,把准备好的安装文件解压,最好建一个顶级目录,如Docker:

unzip docker-images-master.zip

mv linuxx64_12201_database.zip docker-images-master/OracleDatabase/dockerfiles/12.2.0.1/

简单点的日志如下:

bogon:~ eygle$ cd Docker/

bogon:Docker eygle$ ls -l

-rw-r--r--@ 1 eygle staff 4291538 May 16 15:52 docker-images-master.zip

-rw-r--r--@ 1 eygle staff 3453696911 Apr 19 12:04 linuxx64_12201_database.zip

bogon:Docker eygle$ unzip docker-images-master.zip

Archive: docker-images-master.zip

e4dbd20bd3ef245767f37641b5c37d6e918a5f97

creating: docker-images-master/

extracting: docker-images-master/.gitattributes

bogon:Docker eygle$ mv linuxx64_12201_database.zip docker-images-master/OracleDatabase/dockerfiles/12.2.0.1/

第二步:构建数据库的Docker镜像

这个环节就只需要一条命令,需要执行 docker-images-master/OracleDatabase/dockerfiles 下的build脚本:

./buildDockerImage.sh -v 12.2.0.1 -e

在这个步骤中首先需要安装 OEL的 Slim 版本:oraclelinux:7-slim 。需要从网上下载文件,所以安装过程中必须保持网络的连通。整个过程有16个步骤,简单抽取出来,就是类似如下的过程,全部是自动执行的:

Step 1/16 : FROM oraclelinux:7-slim

Step 2/16 : MAINTAINER Gerald Venzl <gerald.venzl@oracle.com>

Step 3/16 : ENV ORACLE_BASE /opt/oracle ORACLE_HOME /opt/oracle/product/12.2.0.1/dbhome_1 INSTALL_FILE_1 "linuxx64_12201_database.zip" INSTALL_RSP "db_inst.rsp" CONFIG_RSP "dbca.rsp.tmpl" PWD_FILE "setPassword.sh" PERL_INSTALL_FILE "installPerl.sh" RUN_FILE "runOracle.sh" START_FILE "startDB.sh" CREATE_DB_FILE "createDB.sh" SETUP_LINUX_FILE "setupLinuxEnv.sh" CHECK_SPACE_FILE "checkSpace.sh" CHECK_DB_FILE "checkDBStatus.sh" INSTALL_DB_BINARIES_FILE "installDBBinaries.sh"

Step 4/16 : ENV INSTALL_DIR $ORACLE_BASE/install PATH $ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH LD_LIBRARY_PATH $ORACLE_HOME/lib:/usr/lib CLASSPATH $ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

Step 5/16 : COPY $INSTALL_FILE_1 $INSTALL_RSP $PERL_INSTALL_FILE $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_DB_BINARIES_FILE $INSTALL_DIR/

Step 6/16 : COPY $RUN_FILE $START_FILE $CREATE_DB_FILE $CONFIG_RSP $PWD_FILE $CHECK_DB_FILE $ORACLE_BASE/

Step 7/16 : RUN chmod ug+x $INSTALL_DIR/*.sh && sync && $INSTALL_DIR/$CHECK_SPACE_FILE && $INSTALL_DIR/$SETUP_LINUX_FILE

Step 8/16 : USER oracle

Step 9/16 : RUN $INSTALL_DIR/$INSTALL_DB_BINARIES_FILE EE

Step 10/16 : USER root

Step 11/16 : RUN $ORACLE_BASE/oraInventory/orainstRoot.sh && $ORACLE_HOME/root.sh && rm -rf $INSTALL_DIR

Step 12/16 : USER oracle

Step 13/16 : WORKDIR /home/oracle

Step 14/16 : VOLUME $ORACLE_BASE/oradata

Step 15/16 : EXPOSE 1521 5500

Step 16/16 : CMD exec $ORACLE_BASE/$RUN_FILE

执行的起点类似如下:

bogon:Docker eygle$ cd docker-images-master/OracleDatabase/dockerfiles

bogon:dockerfiles eygle$ ./buildDockerImage.sh -v 12.2.0.1 -e

完成的终点日志类似:

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 52755 seconds.

第三步:创建和运行数据库

完成了安装之后,你拥有了两个镜像,一个是OEL 7-slim 版本,大约114MB,一个 oracle/database 大约14.8GB。

bogon:OracleDocker eygle$ docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

oracle/database 12.2.0.1-ee dcfea9f4f145 3 hours ago 14.8 GB

oraclelinux 7-slim 442ebf722584 3 weeks ago 114 MB

启动数据库只需要一个命令:

docker run --name oracle -p 1521:1521 -p 5500:5500 -v /Users/eygle/oradata:/opt/oracle/oradata oracle/database:12.2.0.1-ee

这个命令有几个主要参数:-p 指定端口映射,主机到Docker的端口对应;-v 指定数据库的对应存储路径,我指定了一个Docker之外的本地存储,将数据库独立出来。

完成这个命令,会在本地完成数据库的构建并启动数据库,同时输出告警日志的监控。

由于数据库缺省会指定用户口令,所以我们可以通过如下命令来修改口令:

docker exec oracle ./setPassword.sh youpassword

其他的必备命令是:

docker start oracle

docker stop oracle

docker logs oracle

docker ps

接下来就可以在 SQL Developer 里配置和连接这个数据库了:

DockerOracleConfig.jpg

DockerOracleConnect.jpg

当然如果你不想剥离数据库文件出来,也可以用类似以下命令来构建数据库:

docker run -p 1521:1521 --name eygle oracle/database:12.2.0.1-ee

想一想我们第一次安装数据库时的场景,再看看今天的简易程度,我们必须承认,技术在进步,学习越来越简单。Oracle 的今天越加开放和自由,乐趣会越来越多起来!

补充的知识FAQ

1.Docker 的镜像在哪里

在MAC上,位于以下目录,用户换成你的就找到:

/Users/eygle/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2


附录:以下是最后一个步骤,创建数据库的日志输出:

bogon:dockerfiles eygle$ docker run --name oracle -p 1521:1521 -p 5500:5500 -v /Users/eygle/oradata:/opt/oracle/oradata oracle/database:12.2.0.1-ee
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: 2fjRrW5zy8Y=1
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 17-MAY-2017 01:28:54
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/cfb8b54eab11/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 17-MAY-2017 01:28:56
Uptime 0 days 0 hr. 0 min. 2 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/cfb8b54eab11/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-11209] Current available physical memory is less than the required physical memory (2,048MB) for creating the database.
[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/ORCLCDB/ORCLCDB.log" for further details.
SQL*Plus: Release 12.2.0.1.0 Production on Wed May 17 01:37:44 2017
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> 
Pluggable database altered.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
Completed: alter pluggable database ORCLPDB1 open
2017-05-17T01:37:42.901045+00:00
ORCLPDB1(3):CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE 
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K 
MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
ORCLPDB1(3):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING 
DATAFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K 
MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2017-05-17T01:37:44.419029+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
 ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed: ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
2017-05-17T01:47:17.595752+00:00
ORCLPDB1(3):Resize operation completed for file# 10, old size 337920K, new size 358400K
2017-05-17T02:58:14.118529+00:00
Warning: VKTM detected a backward time drift. 
Time drifts can result in unexpected behavior such as time-outs. 
Please see the VKTM trace file for more details:
/opt/oracle/diag/rdbms/orclcdb/ORCLCDB/trace/ORCLCDB_vktm_1723.trc
2017-05-17T03:07:19.070128+00:00
Resize operation completed for file# 3, old size 471040K, new size 481280K
^CStopping container.
SIGINT received, shutting down database!
SQL*Plus: Release 12.2.0.1.0 Production on Wed May 17 04:06:49 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> 2017-05-17T04:06:49.354297+00:00
Shutting down instance (immediate) (OS id: 3434)
2017-05-17T04:06:51.079839+00:00
Stopping background process SMCO
2017-05-17T04:06:52.262508+00:00
Shutting down instance: further logons disabled
2017-05-17T04:06:52.290158+00:00
Stopping background process CJQ0
Stopping background process MMNL
2017-05-17T04:06:53.432719+00:00
Stopping background process MMON
2017-05-17T04:06:53.671235+00:00
OS process OFSD (ospid 1739) idle for 30 seconds, exiting
2017-05-17T04:06:54.534515+00:00
alter pluggable database all close immediate
2017-05-17T04:06:54.578363+00:00
ORCLPDB1(3):JIT: pid 3434 requesting stop
Pluggable database ORCLPDB1 closed
Completed: alter pluggable database all close immediate
PDB$SEED(2):JIT: pid 3434 requesting stop
License high water mark = 18
Dispatchers and shared servers shutdown
2017-05-17T04:06:56.956473+00:00
ALTER DATABASE CLOSE NORMAL
2017-05-17T04:06:57.038966+00:00
Stopping Emon pool
alter pluggable database all close immediate
Completed: alter pluggable database all close immediate
Stopping Emon pool
2017-05-17T04:06:57.139148+00:00
Shutting down archive processes
2017-05-17T04:06:57.141700+00:00
TT00: Gap Manager exiting (PID:1797)
Database closed.
Database dismounted.
2017-05-17T04:06:58.151422+00:00
Archiving is disabled
2017-05-17T04:06:58.155611+00:00
Thread 1 closed at log sequence 2
Successful close of redo thread 1
2017-05-17T04:06:58.461910+00:00
Completed: ALTER DATABASE CLOSE NORMAL
ALTER DATABASE DISMOUNT
Shutting down archive processes
Archiving is disabled
Completed: ALTER DATABASE DISMOUNT
2017-05-17T04:06:59.516713+00:00
ARCH: Archival disabled due to shutdown: 1089
Shutting down archive processes
Archiving is disabled
2017-05-17T04:07:00.533039+00:00
JIT: pid 3434 requesting stop
2017-05-17T04:07:01.593570+00:00
ARCH: Archival disabled due to shutdown: 1089
Shutting down archive processes
Archiving is disabled
JIT: pid 3434 requesting stop
2017-05-17T04:07:01.638769+00:00
Stopping background process VKTM
ORACLE instance shut down.
2017-05-17T04:07:12.390203+00:00
Instance shutdown complete (OS id: 3434)
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 17-MAY-2017 04:07:15
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully

参考文档:

https://sqlmaria.com/2017/04/27/oracle-database-12c-now-available-on-docker/

https://blogs.oracle.com/developer/creating-an-oracle-database-docker-image

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐