1.下载oracle的docker镜像制作工具
链接URL:
https://github.com/oracle/docker-images/archive/refs/heads/main.zip
或
https://codeload.github.com/oracle/docker-images/zip/refs/heads/main
下载docker-images-main.zip
解压至目录~/下。
2.下载oracle12c安装包
复制至目录~/docker-images-main/OracleDatabase/SingleInstance/dockerfiles/12.2.0.1/下。
3.制作oracle12c-ee镜像
3.1系统准备
制作镜像的系统确保****/ 下有15G可用空间。****
3.2制作镜像
$ cd ~/docker-images-main/OracleDatabase/SingleInstance/dockerfiles
$ sudo ./buildContainerImage.sh -v 12.2.0.1 -e
......
Checking Docker version.
Dockerfile
Checking if required packages are present and valid...
linuxx64_12201_database.zip: 成功
==========================
Container runtime info: //容器信息
Client:
Server:
Containers: 1
......
Init Binary: docker-init
containerd version: 2c90293f6964528176db4fc61d3defe7ee281779
runc version: 1.0.0~rc6+dfsg1-3
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.18.17-amd64-desktop-hwe
Operating System: Deepin 20.9
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.62GiB
Docker Root Dir: /var/lib/docker
Registry: https://index.docker.io/v1/
==========================
Building image 'oracle/database:12.2.0.1-ee' ...
Sending build context to Docker daemon 3.454GB
Step 1/22 :
FROM oraclelinux:7-slim as base
7-slim: Pulling from library/oraclelinux
Step 2/22 :
LABEL "provider"="Oracle"
"issues"="https://github.com/oracle/docker-images/issues"
"volume.data"="/opt/oracle/oradata"
"volume.setup.location1"="/opt/oracle/scripts/setup"
"volume.setup.location2"="/docker-entrypoint-initdb.d/setup"
"volume.startup.location1"="/opt/oracle/scripts/startup"
"volume.startup.location2"="/docker-entrypoint-initdb.d/startup"
"port.listener"="1521"
"port.oemexpress"="5500"
Step 3/22 :
ENV ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/12.2.0.1/dbhome_1
INSTALL_DIR=/opt/install
INSTALL_FILE_1="linuxx64_12201_database.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"
Step 4/22 :
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
Step 5/22 :
COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_DIR/
Step 6/22 :
COPY $RUN_FILE $START_FILE $CREATE_DB_FILE $CONFIG_RSP $PWD_FILE $CHECK_DB_FILE $USER_SCRIPTS_FILE $ORACLE_BASE/
Step 7/22 :
RUN chmod ug+x $INSTALL_DIR/*.sh &&
sync &&
$INSTALL_DIR/$CHECK_SPACE_FILE &&
$INSTALL_DIR/$SETUP_LINUX_FILE &&
rm -rf $INSTALL_DIR
Loaded plugins: ovl
Resolving Dependencies //包依赖
......
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
openssl x86_64 1:1.0.2k-26.el7_9 ol7_latest 494 k
oracle-database-server-12cR2-preinstall
x86_64 1.0-5.el7 ol7_latest 19 k
Installing for dependencies:
GeoIP x86_64 1.5.0-14.el7 ol7_latest 1.5 M
acl x86_64 2.2.51-15.el7 ol7_latest 81 k
bc x86_64 1.06.95-13.el7 ol7_latest 114 k
bind-libs x86_64 32:9.11.4-26.P2.el7_9.15 ol7_latest 158 k
bind-libs-lite x86_64 32:9.11.4-26.P2.el7_9.15 ol7_latest 1.1 M
bind-license noarch 32:9.11.4-26.P2.el7_9.15 ol7_latest 91 k
bind-utils x86_64 32:9.11.4-26.P2.el7_9.15 ol7_latest 261 k
binutils x86_64 2.27-44.base.0.3.el7_9.1 ol7_latest 5.4 M
compat-libcap1 x86_64 1.10-7.el7 ol7_latest 17 k
compat-libstdc++-33 x86_64 3.2.3-72.el7 ol7_latest 190 k
cracklib x86_64 2.9.0-11.el7 ol7_latest 79 k
cracklib-dicts x86_64 2.9.0-11.el7 ol7_latest 3.6 M
cronie x86_64 1.4.11-25.el7_9 ol7_latest 92 k
cronie-anacron x86_64 1.4.11-25.el7_9 ol7_latest 36 k
crontabs noarch 1.11-6.20121102git.el7 ol7_latest 12 k
cryptsetup-libs x86_64 2.0.3-6.el7 ol7_latest 338 k
dbus x86_64 1:1.10.24-15.0.1.el7 ol7_latest 245 k
dbus-libs x86_64 1:1.10.24-15.0.1.el7 ol7_latest 169 k
device-mapper x86_64 7:1.02.170-6.0.5.el7_9.5 ol7_latest 297 k
device-mapper-libs x86_64 7:1.02.170-6.0.5.el7_9.5 ol7_latest 325 k
dracut x86_64 033-572.0.13.el7 ol7_latest 331 k
e2fsprogs-libs x86_64 1.42.9-19.0.1.el7 ol7_latest 168 k
elfutils-default-yama-scope noarch 0.176-5.el7 ol7_latest 32 k
elfutils-libs x86_64 0.176-5.el7 ol7_latest 290 k
ethtool x86_64 2:4.8-10.el7 ol7_latest 126 k
fipscheck x86_64 1.4.1-6.el7 ol7_latest 21 k
fipscheck-lib x86_64 1.4.1-6.el7 ol7_latest 10 k
geoipupdate x86_64 2.5.0-2.el7 ol7_latest 34 k
glibc-devel x86_64 2.17-326.0.9.el7_9 ol7_latest 1.1 M
glibc-headers x86_64 2.17-326.0.9.el7_9 ol7_latest 694 k
gssproxy x86_64 0.7.0-30.el7_9 ol7_latest 110 k
gzip x86_64 1.5-11.el7_9 ol7_latest 129 k
hardlink x86_64 1:1.0-19.el7 ol7_latest 14 k
hostname x86_64 3.13-3.el7_7.1 ol7_latest 16 k
initscripts x86_64 9.49.53-1.0.3.el7_9.1 ol7_latest 443 k
iproute x86_64 4.11.0-30.el7 ol7_latest 805 k
iptables x86_64 1.4.21-35.0.3.el7 ol7_latest 432 k
iputils x86_64 20160308-10.el7 ol7_latest 147 k
json-c x86_64 0.11-4.el7_0 ol7_latest 30 k
kernel-headers x86_64 3.10.0-1160.114.2.0.1.el7 ol7_latest 9.1 M
keyutils x86_64 1.5.8-3.el7 ol7_latest 53 k
kmod x86_64 20-28.0.3.el7 ol7_latest 125 k
kmod-libs x86_64 20-28.0.3.el7 ol7_latest 53 k
kpartx x86_64 0.4.9-136.0.3.el7_9 ol7_latest 81 k
ksh x86_64 20120801-144.0.1.el7_9 ol7_latest 882 k
libICE x86_64 1.0.9-9.el7 ol7_latest 66 k
libSM x86_64 1.2.2-2.el7 ol7_latest 39 k
libX11 x86_64 1.6.7-5.el7_9 ol7_latest 607 k
libX11-common noarch 1.6.7-5.el7_9 ol7_latest 164 k
libXau x86_64 1.0.8-2.1.el7 ol7_latest 28 k
libXext x86_64 1.3.3-3.el7 ol7_latest 38 k
libXi x86_64 1.7.9-1.el7 ol7_latest 40 k
libXinerama x86_64 1.1.3-2.1.el7 ol7_latest 13 k
libXmu x86_64 1.1.2-2.el7 ol7_latest 70 k
libXrandr x86_64 1.5.1-2.el7 ol7_latest 27 k
libXrender x86_64 0.9.10-1.el7 ol7_latest 25 k
libXt x86_64 1.1.5-3.el7 ol7_latest 172 k
libXtst x86_64 1.2.3-1.el7 ol7_latest 20 k
libXv x86_64 1.0.11-1.el7 ol7_latest 18 k
libXxf86dga x86_64 1.1.4-2.1.el7 ol7_latest 18 k
libXxf86misc x86_64 1.0.3-7.1.el7 ol7_latest 19 k
libXxf86vm x86_64 1.1.4-1.el7 ol7_latest 17 k
libaio x86_64 0.3.109-13.el7 ol7_latest 24 k
libaio-devel x86_64 0.3.109-13.el7 ol7_latest 12 k
libbasicobjects x86_64 0.1.1-32.el7 ol7_latest 25 k
libcollection x86_64 0.7.0-32.el7 ol7_latest 41 k
libdmx x86_64 1.1.3-3.el7 ol7_latest 15 k
libedit x86_64 3.0-12.20121213cvs.el7 ol7_latest 88 k
libevent x86_64 2.0.21-4.el7 ol7_latest 208 k
libini_config x86_64 1.3.1-32.el7 ol7_latest 63 k
libmnl x86_64 1.0.3-7.el7 ol7_latest 22 k
libnetfilter_conntrack x86_64 1.0.6-1.el7_3 ol7_latest 55 k
libnfnetlink x86_64 1.0.1-4.el7 ol7_latest 25 k
libnfsidmap x86_64 0.25-19.el7 ol7_latest 49 k
libpath_utils x86_64 0.2.1-32.el7 ol7_latest 28 k
libpwquality x86_64 1.2.3-5.el7 ol7_latest 84 k
libref_array x86_64 0.1.5-32.el7 ol7_latest 27 k
libsmartcols x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 143 k
libstdc++-devel x86_64 4.8.5-44.0.3.el7 ol7_latest 1.5 M
libtirpc x86_64 0.2.4-0.16.el7 ol7_latest 89 k
libuser x86_64 0.60-9.el7 ol7_latest 400 k
libutempter x86_64 1.1.6-4.el7 ol7_latest 24 k
libverto-libevent x86_64 0.2.5-4.el7 ol7_latest 8.2 k
libxcb x86_64 1.13-1.el7 ol7_latest 213 k
lm_sensors-libs x86_64 3.4.0-8.20160601gitf9185e5.0.1.el7_9.1
ol7_latest 42 k
lz4 x86_64 1.8.3-1.el7 ol7_latest 84 k
mailx x86_64 12.5-19.el7 ol7_latest 244 k
make x86_64 1:3.82-24.el7 ol7_latest 420 k
net-tools x86_64 2.0-0.25.20131004git.el7 ol7_latest 305 k
nfs-utils x86_64 1:1.3.0-0.68.0.1.el7.2 ol7_latest 413 k
openssh x86_64 7.4p1-23.0.3.el7_9 ol7_latest 485 k
openssh-clients x86_64 7.4p1-23.0.3.el7_9 ol7_latest 655 k
pam x86_64 1.1.8-23.el7 ol7_latest 720 k
pkgconfig x86_64 1:0.27.1-4.el7 ol7_latest 53 k
procps-ng x86_64 3.3.10-28.0.1.el7 ol7_latest 291 k
psmisc x86_64 22.20-17.el7 ol7_latest 141 k
qrencode-libs x86_64 3.4.1-3.el7 ol7_latest 49 k
quota x86_64 1:4.01-19.el7 ol7_latest 178 k
quota-nls noarch 1:4.01-19.el7 ol7_latest 90 k
rpcbind x86_64 0.2.0-49.el7 ol7_latest 59 k
smartmontools x86_64 1:7.0-2.el7 ol7_latest 546 k
sysstat x86_64 10.1.5-20.0.3.el7_9 ol7_latest 316 k
systemd x86_64 219-78.0.13.el7_9.9 ol7_latest 5.1 M
systemd-libs x86_64 219-78.0.13.el7_9.9 ol7_latest 421 k
systemd-sysv x86_64 219-78.0.13.el7_9.9 ol7_latest 99 k
sysvinit-tools x86_64 2.88-14.dsf.el7 ol7_latest 62 k
tar x86_64 2:1.26-35.el7 ol7_latest 845 k
tcp_wrappers x86_64 7.6-77.el7 ol7_latest 78 k
tcp_wrappers-libs x86_64 7.6-77.el7 ol7_latest 65 k
unzip x86_64 6.0-24.0.1.el7_9 ol7_latest 172 k
util-linux x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 2.0 M
xorg-x11-utils x86_64 7.5-23.el7 ol7_latest 114 k
xorg-x11-xauth x86_64 1:1.0.9-1.el7 ol7_latest 29 k
xz x86_64 5.2.2-2.el7_9 ol7_latest 228 k
Updating for dependencies:
glibc x86_64 2.17-326.0.9.el7_9 ol7_latest 3.6 M
glibc-common x86_64 2.17-326.0.9.el7_9 ol7_latest 12 M
libblkid x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 183 k
libcom_err x86_64 1.42.9-19.0.1.el7 ol7_latest 42 k
libmount x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 185 k
libuuid x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 84 k
openssl-libs x86_64 1:1.0.2k-26.el7_9 ol7_latest 1.2 M
xz-libs x86_64 5.2.2-2.el7_9 ol7_latest 103 k
Transaction Summary
================================================================================
Install 2 Packages (+114 Dependent packages)
Upgrade ( 8 Dependent packages)
Total download size: 65 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
--------------------------------------------------------------------------------
Total 857 kB/s | 65 MB 01:18
......
Installed:
openssl.x86_64 1:1.0.2k-26.el7_9
oracle-database-server-12cR2-preinstall.x86_64 0:1.0-5.el7
Dependency Installed:
Complete!
Step 8/22 :
FROM base AS builder
Step 9/22 :
ARG DB_EDITION
Step 10/22 :
RUN yum -y install unzip
Step 11/22 :
COPY --chown=oracle:dba $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_DB_BINARIES_FILE $INSTALL_DIR/
Step 12/22 :
USER oracle
Step 13/22 :
RUN chmod ug+x $INSTALL_DIR/*.sh &&
sync &&
$INSTALL_DIR/$INSTALL_DB_BINARIES_FILE $DB_EDITION
Archive: linuxx64_12201_database.zip //解压
inflating: database/runInstaller
Starting Oracle Universal Installer... //安装oracle12cc
......
Successfully Setup Software.
Step 14/22 :
FROM base
Step 15/22 :
USER oracle
Step 16/22 :
COPY --chown=oracle:dba --from=builder $ORACLE_BASE $ORACLE_BASE
Step 17/22 :
USER root
Step 18/22 :
RUN $ORACLE_BASE/oraInventory/orainstRoot.sh &&
$ORACLE_HOME/root.sh
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.
Step 19/22 :
USER oracle
Step 20/22 :
WORKDIR /home/oracle
Step 21/22 :
HEALTHCHECK --interval=1m --start-period=5m CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1
Step 22/22 :
CMD exec $ORACLE_BASE/$RUN_FILE
Successfully built 358073b899d3
Successfully tagged oracle/database:12.2.0.1-ee
Oracle Database container image for 'ee' version 12.2.0.1 is ready to be extended:
--> oracle/database:12.2.0.1-ee
Build completed in 707 seconds.
3.3查看创建的镜像
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/database 12.2.0.1-ee 358073b899d3 2 hours ago 6.15GB
oraclelinux 7-slim 5ca608cbbc7a 2 years ago 132MB
4.创建容器
4.1新建oracle用户以及对应的组
$ sudo groupadd -g 54321 oinstall
$ sudo groupadd -g 54322 dba
$ sudo groupadd -g 54323 oper
$ sudo groupadd -g 54324 backupdba
$ sudo groupadd -g 54325 dgdba
$ sudo groupadd -g 54325 kmdba
$ sudo groupadd -g 54330 racdba
$ sudo useradd -u 54321 -g oinstall -G dba,oper -md /home/oracle -s /bin/bash oracle
$ echo "oracle:oracle" | sudo chpasswd
4.2创建数据存放目录并授权
$ sudo mkdir -p /opt/oracle/oradata
$ chown -Rf oracle:oinstall /opt/oracle/oradata
4.3运行创建容器
$ sudo docker run --name <container name> \
-p <host port>:1521 -p <host port>:5500 -p <host port>:2484 \
--ulimit nofile=1024:65536 --ulimit nproc=2047:16384 --ulimit stack=10485760:33554432 --ulimit memlock=3221225472 \
-e ORACLE_SID=<your SID> \
-e ORACLE_PDB=<your PDB name> \
-e ORACLE_PWD=<your database passwords> \
-e INIT_SGA_SIZE=<your database SGA memory in MB> \
-e INIT_PGA_SIZE=<your database PGA memory in MB> \
-e INIT_CPU_COUNT=<cpu_count init-parameter> \
-e INIT_PROCESSES=<processes init-parameter> \
-e ORACLE_EDITION=<your database edition> \
-e ORACLE_CHARACTERSET=<your character set> \
-e ENABLE_ARCHIVELOG=true \
-e ENABLE_TCPS=true \
-v [<host mount point>:]/opt/oracle/oradata \
oracle/database:21.3.0-ee
参数:
|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| --name | 容器名,可自动生成 |
| -p | 主机端口映射容器端口:1521 (Oracle 侦听) 5500 (web管理器) 2484 (TCPS加密协议侦听) |
| --ulimit memlock= | 资源限制 |
| -e ORACLE_SID=<SID> | 实例名,默认为ORCLCDB |
| -e ORACLE_PDB=<PDB name> | PDB名,默认为ORCLPDB1 |
| -e ORACLE_PWD=<password> | 库管密码,可自动生成 也可之后设置: docker exec <容器> ./setPassword.sh <新密码> |
| -e INIT_SGA_SIZE= | SGA大小(单位MB),可选 |
| -e INIT_PGA_SIZE= | PGA大小(单位MB),可选 |
| -e INIT_CPU_COUNT= | Oracle可使用CPU数,可选 |
| -e INIT_PROCESSES= | Oracle可用用户并发进程,可选 |
| -e AUTO_MEM_CALCULATION | true默认,DBCA依据--memory选项值启用内存自动计算 false不启用,使用2GB内存 注意设置参数`-e INIT_SGA_SIZE` 或 `-e INIT_PGA_SIZE`时不启用 |
| -e ORACLE_EDITION=[enterprise|standard] | oracle版本,可以运行时更改 |
| -e ORACLE_CHARACTERSET=[AL32UTF8] | 库字符集,默认为AL32UTF8 |
| -e ENABLE_ARCHIVELOG= | true,启用归档,归档日志路径: /opt/oracle/oradata/$ORACLE_SID/archive_logs False默认,不启用归档 |
| -e ENABLE_TCPS= | true,启用TCPS加密连接 False默认,不启用加密连接 |
| -e TCPS_CERTS_LOCATION | 定位TCPS加密连接使用的SSL证书 |
| -v [主机数据路径]:/opt/oracle/oradata | 库数据卷映射,要求用户oracle(uid: 54321) 可写 缺省时不保存数据 |
| -v /opt/oracle/scripts/startup | /docker-entrypoint-initdb.d/startup | 可选,库启动后运行的自定义启动脚本 |
| -v /opt/oracle/scripts/setup | /docker-entrypoint-initdb.d/setup | 可选,库设置后运行的自定义设置脚本 |
实例:
$ sudo docker run --name oracle12c-ee \
-p 1521:1521 -p 5500:5500 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=pdb \
-e ORACLE_PWD=manager \
-e INIT_SGA_SIZE=8000 \
-e INIT_PGA_SIZE=1000 \
-e ORACLE_CHARACTERSET=ZHS16GBK \
-v /opt/oracle/oradata:/opt/oracle/oradata \
oracle/database:12.2.0.1-ee
5.容器内操作
5.1进入容器
$ sudo docker exec -it oracle12c-ee /bin/bash
[oracle@b671a12012fd ~]$ export ORACLE_SID=ORCL
[oracle@b671a12012fd ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sun Apr 7 03:22:00 2024
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
5.2查看pdb
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
5.3查看当前连接的库
SQL> SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
5.4切换当前库
SQL> alter session set container=pdb;
Session altered.
5.5关闭
SQL> shutdown immediate;