如何获得一个单实例Oracle数据库(从Github - oracle/docker-images)

屠和洽
2023-12-01

环境

一台笔记本电脑,Windows操作系统,安装了VirtualBox,Vagrant,Github。

目标

操作系统Oracle Linux 7,运行容器数据库,单实例数据库企业版,版本为19.3.0,实例名为ORCLCDB,带一个可插拔数据库orclpdb1。

创建Linux操作系统

克隆项目以获得Linux Vagrant Box,如果您已经有一台Linux主机如云主机,则无需此步:

PS D:\DB> git clone https://github.com/oracle/vagrant-boxes.git

在Vagrantfile中将内存由默认的2048改为4096(或者比2048略大,因为最终运行的容器需要2G内存,否则会警告),然后创建虚机(Oracle Linux 7)。耗时7分1秒。

PS E:\DB\vagrant-boxes\OracleLinux\7> Measure-Command { vagrant up | Out-Default}

前几天有人问到,现补充如何在Vagrantfile中修改内存的方法,修改下面代码中4096处即可:

# change memory size
  config.vm.provider "virtualbox" do |v|
    v.memory = 4096
    v.name = NAME
  end
  config.vm.provider :libvirt do |v|
    v.memory = 2048
  end

以下操作均登入Linux中运行。

安装Docker

安装Docker,耗时1m32.087s:

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 usermod -aG docker vagrant

确认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组:

$ id vagrant
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),10(wheel),993(docker)

克隆Github项目

耗时0m31.781s:

sudo yum install -y git
git clone https://github.com/oracle/docker-images.git

将安装文件拷贝到目录

耗时0m22.910s:

$ cp /vagrant/LINUX.X64_193000_db_home.zip ~/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0

Build Docker Image

笔记本上做耗时25m6.343s(Oracle公有云计算实例耗时14m53.180s):

$ cd docker-images/OracleDatabase/SingleInstance/dockerfiles/
$ ls
11.2.0.2  12.1.0.2  12.2.0.1  18.3.0  18.4.0  19.3.0  buildDockerImage.sh
$ ./buildDockerImage.sh -v 19.3.0 -e

日志如下:

Checking if required packages are present and valid...
LINUX.X64_193000_db_home.zip: OK
==========================
DOCKER info:
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.8-ol
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39
runc version: 4bb1fe4ace1a32d3676bb98f5d3b6a4e32bf6c58
init version: fec3683
Security Options:
 seccomp
  Profile: default
 selinux
Kernel Version: 4.14.35-1902.6.6.el7uek.x86_64
Operating System: Oracle Linux Server 7.7
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.685GiB
Name: ol7-vagrant-test
ID: 2EWW:K3PE:2XKC:2HGG:FLRI:NPDC:SDPA:KYNC:3C74:VLOW:A6VM:UZFH
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
Product License: Community Engine

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Registries: docker.io (secure)
==========================
Building image 'oracle/database:19.3.0-ee' ...
Sending build context to Docker daemon   3.06GB
Step 1/23 : FROM oraclelinux:7-slim as base
Trying to pull repository docker.io/library/oraclelinux ...
7-slim: Pulling from docker.io/library/oraclelinux
a316717fc6ee: Pull complete
Digest: sha256:c5f3baff726ffd97c7e9574e803ad0e8a1e5c7de236325eed9e87f853a746e90
Status: Downloaded newer image for oraclelinux:7-slim
 ---> 874477adb545
Step 2/23 : MAINTAINER Gerald Venzl <gerald.venzl@oracle.com>
 ---> Running in 99c985e056f1
Removing intermediate container 99c985e056f1
 ---> 248e88ec1a9c
Step 3/23 : ENV ORACLE_BASE=/opt/oracle     ORACLE_HOME=/opt/oracle/product/19c/dbhome_1     INSTALL_DIR=/opt/install     INSTALL_FILE_1="LINUX.X64_193000_db_home.zip"     INSTALL_RSP="db_inst.rsp"     CONFIG_RSP="dbca.rsp.tmpl"     PWD_FILE="setPassword.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"     USER_SCRIPTS_FILE="runUserScripts.sh"     INSTALL_DB_BINARIES_FILE="installDBBinaries.sh"
 ---> Running in c3ca3880635f
Removing intermediate container c3ca3880635f
 ---> 55798a1b1572
Step 4/23 : ENV 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
 ---> Running in 766bf6c87ed8
Removing intermediate container 766bf6c87ed8
 ---> 83f2dd8b0407
Step 5/23 : COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_DIR/
 ---> 774a3b4a8696
Step 6/23 : COPY $RUN_FILE $START_FILE $CREATE_DB_FILE $CONFIG_RSP $PWD_FILE $CHECK_DB_FILE $USER_SCRIPTS_FILE $ORACLE_BASE/
 ---> c8afaf0d18a1
Step 7/23 : RUN chmod ug+x $INSTALL_DIR/*.sh &&     sync &&     $INSTALL_DIR/$CHECK_SPACE_FILE &&     $INSTALL_DIR/$SETUP_LINUX_FILE &&     rm -rf $INSTALL_DIR
 ---> Running in 52d033e0ccfd
Loaded plugins: ovl
Resolving Dependencies
--> Running transaction check
---> Package openssl.x86_64 1:1.0.2k-19.0.1.el7 will be installed
...
Complete!
Removing intermediate container 52d033e0ccfd
 ---> 59695647e116
Step 8/23 : FROM base AS builder
 ---> 59695647e116
Step 9/23 : ARG DB_EDITION
 ---> Running in 5d16bf1aa8f7
Removing intermediate container 5d16bf1aa8f7
 ---> cc2c66c80a3e
Step 10/23 : COPY --chown=oracle:dba $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_DB_BINARIES_FILE $INSTALL_DIR/
 ---> b11ad4746cbe
Step 11/23 : USER oracle
 ---> Running in aee1be2cf384
Removing intermediate container aee1be2cf384
 ---> 6c25c71c7c60
Step 12/23 : RUN chmod ug+x $INSTALL_DIR/*.sh &&     sync &&     $INSTALL_DIR/$INSTALL_DB_BINARIES_FILE $DB_EDITION
 ---> Running in 0d3c8c894c69
...
Step 13/23 : FROM base
 ---> 59695647e116
Step 14/23 : USER oracle
 ---> Running in 13931064b7c0
Removing intermediate container 13931064b7c0
 ---> b7fbda98c11b
Step 15/23 : COPY --chown=oracle:dba --from=builder $ORACLE_BASE $ORACLE_BASE

 ---> 4d326ac38dd6
Step 16/23 : USER root
 ---> Running in 8739d62324fb
Removing intermediate container 8739d62324fb
 ---> 0db2d5e81ab9
Step 17/23 : RUN $ORACLE_BASE/oraInventory/orainstRoot.sh &&     $ORACLE_HOME/root.sh
 ---> Running in 99939157b040
Changing permissions of /opt/oracle/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /opt/oracle/oraInventory to dba.
The execution of the script is complete.
Check /opt/oracle/product/19c/dbhome_1/install/root_99939157b040_2019-11-08_07-12-28-865653640.log for the output of root script
Removing intermediate container 99939157b040
 ---> b1a2c7cfcb43
Step 18/23 : USER oracle
 ---> Running in 44d65901d878
Removing intermediate container 44d65901d878
 ---> 1c374ce65dcb
Step 19/23 : WORKDIR /home/oracle
 ---> Running in bef865835327
Removing intermediate container bef865835327
 ---> fb77e9025700
Step 20/23 : VOLUME ["$ORACLE_BASE/oradata"]
 ---> Running in 783770da9e1f
Removing intermediate container 783770da9e1f
 ---> b449e8377cdf
Step 21/23 : EXPOSE 1521 5500
 ---> Running in ff9dc984e35d
Removing intermediate container ff9dc984e35d
 ---> 2b989220f8b0
Step 22/23 : HEALTHCHECK --interval=1m --start-period=5m    CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1
 ---> Running in e27b220e4742
Removing intermediate container e27b220e4742
 ---> bd9ca78b3b87
Step 23/23 : CMD exec $ORACLE_BASE/$RUN_FILE
 ---> Running in c67b27781285
Removing intermediate container c67b27781285
 ---> 0fa7c9910b5f
Successfully built 0fa7c9910b5f
Successfully tagged oracle/database:19.3.0-ee


  Oracle Database Docker Image for 'ee' version 19.3.0 is ready to be extended:

    --> oracle/database:19.3.0-ee

  Build completed in 1500 seconds.

至此,数据库的docker image就绪了。linux image使用的瘦身版,例如vi就没有。数据库image只是安装了数据库软件,但未创建数据库实例。

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
oracle/database     19.3.0-ee           15951bb18900        About a minute ago   6.65GB
oraclelinux         7-slim              874477adb545        3 months ago         118MB

创建数据库容器

此步骤耗时18分钟。如果是Oracle公有云上的计算实例,耗时居然也是18分钟。看来这部分与网络无关。
此部分会利用dbca创建数据库实例和一个PDB。

time docker run --name odbee193 \
    -d \
    -p 51521:1521 \
    -p 55500:5500 \
    -e ORACLE_PWD=AB_cd_1234 \
    -e ORACLE_CHARACTERSET=AL32UTF8 \
    oracle/database:19.3.0-ee

此时容器状态显示(health: starting),说明数据库未就绪:

$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                             PORTS                                              NAMES
ceb3e0f19fee        oracle/database:19.3.0-ee   "/bin/sh -c 'exec $O…"   31 seconds ago      Up 30 seconds (health: starting)   0.0.0.0:51521->1521/tcp, 0.0.0.0:55500->5500/tcp   odbee193

此时可以立即登录到操作系统,但数据库需要等到创建完成后才可连接(使用dbca silent mode):

docker exec -it odbee193 bash

可以看到dbca正在运行:

$ ps -ef|grep dbca
oracle      28    16 26 07:56 ?        00:00:19 /opt/oracle/product/19c/dbhome_1/jdk/jre/bin/java -Doracle.installer.not_bootstrap=true -DCV_HOME=/opt/oracle/product/19c/dbhome_1 -DORACLE_HOME=/opt/oracle/product/19c/dbhome_1 -XX:-OmitStackTraceInFastThrow -XX:CompileCommand=quiet -XX:CompileCommand=exclude,javax/swing/text/GlyphView,getBreakSpot -Djava.security.egd=file:/dev/urandom -DSET_LAF= -Dsun.java2d.font.DisableAlgorithmicStyles=true -Dice.pilots.html4.ignoreNonGenericFonts=true -DDISPLAY= -DJDBC_PROTOCOL=thin -mx512m -classpath /opt/oracle/product/19c/dbhome_1/assistants/dbca/jlib/dbca.jar:/opt/oracle/product/19c/dbhome_1/assistants/dbca/jlib/dbcaext.jar:/opt/oracle/product/19c/dbhome_1/assistants/jlib/assistantsCommon.jar:/opt/oracle/product/19c/dbhome_1/assistants/jlib/rconfig.jar:/opt/oracle/product/19c/dbhome_1/assistants/jlib/asstcommonext.jar:/opt/oracle/product/19c/dbhome_1/jlib/srvm.jar:/opt/oracle/product/19c/dbhome_1/jlib/srvmhas.jar:/opt/oracle/product/19c/dbhome_1/jlib/srvmasm.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/OraInstaller.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/OraPrereq.jar:/opt/oracle/product/19c/dbhome_1/inventory/prereqs/oui/OraPrereqChecks.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/OraPrereqChecks.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/OraCheckPoint.jar:/opt/oracle/product/19c/dbhome_1/jlib/cvu.jar:/opt/oracle/product/19c/dbhome_1/install/jlib/installcommons_1.0.0b.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/jewt4.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/ssh.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/jsch.jar:/opt/oracle/product/19c/dbhome_1/jlib/ewt3.jar:/opt/oracle/product/19c/dbhome_1/jlib/ewtcompat-3_3_15.jar:/opt/oracle/product/19c/dbhome_1/jlib/share.jar:/opt/oracle/product/19c/dbhome_1/jlib/help4.jar:/opt/oracle/product/19c/dbhome_1/oui/jlib/jewt4.jar:/opt/oracle/product/19c/dbhome_1/jlib/oracle_ice.jar:/opt/oracle/product/19c/dbhome_1/jlib/kodiak.jar:/opt/oracle/product/19c/dbhome_1/lib/xmlparserv2.jar:/opt/oracle/product/19c/dbhome_1/jlib/orai18n.jar:/opt/oracle/product/19c/dbhome_1/jlib/ldapjclnt19.jar:/opt/oracle/product/19c/dbhome_1/jlib/netcfg.jar:/opt/oracle/product/19c/dbhome_1/jlib/ojmisc.jar:/opt/oracle/product/19c/dbhome_1/jlib/oraclepki.jar:/opt/oracle/product/19c/dbhome_1/jlib/opm.jar:/opt/oracle/product/19c/dbhome_1/jdbc/lib/ojdbc8.jar:/opt/oracle/product/19c/dbhome_1/dv/jlib/dvca.jar:/opt/oracle/product/19c/dbhome_1/jlib/gns.jar:/opt/oracle/product/19c/dbhome_1/jlib/commons-compress-1.18.jar oracle.assistants.dbca.driver.DBConfigurator -silent -createDatabase -responseFile /opt/oracle/dbca.rsp
oracle     629   610  0 07:57 pts/0    00:00:00 grep --color=auto dbca

可以查看运行容器的执行日志,日志中记录了时间:

$ docker logs -f odbee193
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: AB_cd_1234

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 09-NOV-2019 07:56:02

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/ceb3e0f19fee/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 19.0.0.0.0 - Production
Start Date                09-NOV-2019 07:56:02
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/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/ceb3e0f19fee/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
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/ORCLCDB.
Database Information:
Global Database Name:ORCLCDB
System Identifier(SID):ORCLCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Nov 9 08:14:08 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>
System altered.

SQL>
System altered.

SQL>
Pluggable database altered.

SQL>
PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
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:
ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2019-11-09T08:14:08.194569+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
2019-11-09T08:14:08.208013+00:00
ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
   ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE

XDB initialized.

等待状态变为(healthy)即表示数据库就绪:

$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                    PORTS                                              NAMES
ceb3e0f19fee        oracle/database:19.3.0-ee   "/bin/sh -c 'exec $O…"   21 minutes ago      Up 21 minutes (healthy)   0.0.0.0:51521->1521/tcp, 0.0.0.0:55500->5500/tcp   odbee193

从容器内部登录数据库:

[opc@instance-20191115-storageserver dockerfiles]$ docker exec -it odbee193 bash
[oracle@2f4f8670e6ed ~]$ echo $ORACLE_HOME
/opt/oracle/product/19c/dbhome_1
[oracle@2f4f8670e6ed ~]$ echo $ORACLE_SID

[oracle@2f4f8670e6ed ~]$ cat /etc/oratab
#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
ORCLCDB:/opt/oracle/product/19c/dbhome_1:N

[oracle@2f4f8670e6ed ~]$ . oraenv
ORACLE_SID = [] ? ORCLCDB
The Oracle base remains unchanged with value /opt/oracle
[oracle@2f4f8670e6ed ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 19 11:22:45 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select name from v$database;

NAME
---------
ORCLCDB

SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@2f4f8670e6ed ~]$ exit
exit

从外部登录数据库需要安装Oracle客户端,可以采取docker方式,详见这里
过程如下:

$ pwd
/home/opc/docker-images/OracleInstantClient/dockerfiles/19

$ docker build --pull -t oracle/instantclient:19 .
Sending build context to Docker daemon   5.12kB
Step 1/5 : FROM oraclelinux:7-slim
Trying to pull repository docker.io/library/oraclelinux ...
7-slim: Pulling from docker.io/library/oraclelinux
Digest: sha256:0743f72832d8744a89b7be31b38b9fb2e5390044cbb153cd97b3e797723e4704
Status: Image is up to date for oraclelinux:7-slim
 ---> c2b5cb5bcd9d
Step 2/5 : ARG release=19
 ---> Running in 5cca51dcab82
Removing intermediate container 5cca51dcab82
 ---> dcea210d504b
Step 3/5 : ARG update=3
 ---> Running in 3a617060d976
Removing intermediate container 3a617060d976
 ---> f326cf029b55
Step 4/5 : RUN  yum -y install oracle-release-el7 && yum-config-manager --enable ol7_oracle_instantclient &&      yum -y install oracle-instantclient${release}.${update}-basic oracle-instantclient${release}.${update}-devel oracle-instantclient${release}.${update}-sqlplus &&      rm -rf /var/cache/yum
 ---> Running in 0b5b40192fa0
Loaded plugins: ovl
Resolving Dependencies
--> Running transaction check
---> Package oracle-release-el7.x86_64 0:1.0-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch         Version           Repository        Size
================================================================================
Installing:
 oracle-release-el7       x86_64       1.0-2.el7         ol7_latest        14 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 14 k
Installed size: 18 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : oracle-release-el7-1.0-2.el7.x86_64                          1/1
  Verifying  : oracle-release-el7-1.0-2.el7.x86_64                          1/1

Installed:
  oracle-release-el7.x86_64 0:1.0-2.el7

Complete!
Loaded plugins: ovl
======================== repo: ol7_oracle_instantclient ========================
[ol7_oracle_instantclient]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7Server
baseurl = http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7Server/ol7_oracle_instantclient
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = True
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7Server/ol7_oracle_instantclient/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7Server/ol7_oracle_instantclient/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
hdrdir = /var/cache/yum/x86_64/7Server/ol7_oracle_instantclient/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Oracle Intant Client for Oracle Linux 7Server (x86_64)
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7Server/ol7_oracle_instantclient
pkgdir = /var/cache/yum/x86_64/7Server/ol7_oracle_instantclient/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = ol7_oracle_instantclient/x86_64
ui_repoid_vars = releasever,
   basearch
username =

Loaded plugins: ovl
Resolving Dependencies
--> Running transaction check
---> Package oracle-instantclient19.3-basic.x86_64 0:19.3.0.0.0-1 will be installed
--> Processing Dependency: libaio for package: oracle-instantclient19.3-basic-19.3.0.0.0-1.x86_64
---> Package oracle-instantclient19.3-devel.x86_64 0:19.3.0.0.0-1 will be installed
---> Package oracle-instantclient19.3-sqlplus.x86_64 0:19.3.0.0.0-1 will be installed
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                   Arch   Version        Repository                Size
================================================================================
Installing:
 oracle-instantclient19.3-basic
                           x86_64 19.3.0.0.0-1   ol7_oracle_instantclient  51 M
 oracle-instantclient19.3-devel
                           x86_64 19.3.0.0.0-1   ol7_oracle_instantclient 598 k
 oracle-instantclient19.3-sqlplus
                           x86_64 19.3.0.0.0-1   ol7_oracle_instantclient 686 k
Installing for dependencies:
 libaio                    x86_64 0.3.109-13.el7 ol7_latest                24 k

Transaction Summary
================================================================================
Install  3 Packages (+1 Dependent package)

Total download size: 53 M
Installed size: 230 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               38 MB/s |  53 MB  00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libaio-0.3.109-13.el7.x86_64                                 1/4
  Installing : oracle-instantclient19.3-basic-19.3.0.0.0-1.x86_64           2/4
  Installing : oracle-instantclient19.3-sqlplus-19.3.0.0.0-1.x86_64         3/4
  Installing : oracle-instantclient19.3-devel-19.3.0.0.0-1.x86_64           4/4
  Verifying  : oracle-instantclient19.3-basic-19.3.0.0.0-1.x86_64           1/4
  Verifying  : libaio-0.3.109-13.el7.x86_64                                 2/4
  Verifying  : oracle-instantclient19.3-sqlplus-19.3.0.0.0-1.x86_64         3/4
  Verifying  : oracle-instantclient19.3-devel-19.3.0.0.0-1.x86_64           4/4

Installed:
  oracle-instantclient19.3-basic.x86_64 0:19.3.0.0.0-1
  oracle-instantclient19.3-devel.x86_64 0:19.3.0.0.0-1
  oracle-instantclient19.3-sqlplus.x86_64 0:19.3.0.0.0-1

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7

Complete!
Removing intermediate container 0b5b40192fa0
 ---> d218dcf3bff4
Step 5/5 : CMD ["sqlplus", "-v"]
 ---> Running in e093d86eef52
Removing intermediate container e093d86eef52
 ---> 61b0e6823699
Successfully built 61b0e6823699
Successfully tagged oracle/instantclient:19

客户端安装完成后,首先获取一些地址:

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' odbee193
172.17.0.2
$ hostname -i
10.0.1.25
$ netstat -an|grep 1521
tcp6       0      0 :::51521                :::*                    LISTEN
$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                    PORTS                                              NAMES
2f4f8670e6ed        oracle/database:19.3.0-ee   "/bin/sh -c 'exec $O…"   34 minutes ago      Up 34 minutes (healthy)   0.0.0.0:51521->1521/tcp, 0.0.0.0:55500->5500/tcp   odbee193

测试通过sqlplus连接,使用docker host地址可以(我是在关闭防火墙之后才行的),使用容器地址172.17.0.2和localhost不行:


$ 
docker run -ti --rm oracle/instantclient:19 sqlplus system/AB_cd_1234@//10.0.1.25:51521/ORCLCDB

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 19 11:32:20 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select CREATED from v$database;

CREATED
---------
19-NOV-19


遗留问题

由于我之前停掉了防火墙,重启容器报错如下:

$ docker restart odbee193
Error response from daemon: Cannot restart container odbee193: driver failed programming external connectivity on endpoint odbee193 (202d4366db89c63efc994030a7212d5a9df52b72f231ace6a0ed493d22eb5070):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 55500 -j DNAT --to-destination 172.17.0.2:5500 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1))

启动防火墙,docker run成功。但此时又必须关掉防火墙才能连接数据库。是个怪圈。

参考

  1. https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance
  2. https://blogs.oracle.com/pwc/the-docker-is-in-for-the-dba-oracle-database-with-docker-and-kubernetes-too
  3. https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers
 类似资料: