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-initcontainerd version: 2c90293f6964528176db4fc61d3defe7ee281779runc version: 1.0.0~rc6+dfsg1-3init version: fec3683Security Options:apparmorseccompProfile: defaultKernel Version: 5.18.17-amd64-desktop-hweOperating System: Deepin 20.9OSType: linuxArchitecture: x86_64CPUs: 8Total Memory: 15.62GiBDocker Root Dir: /var/lib/dockerRegistry: https://index.docker.io/v1/
==========================
Building image 'oracle/database:12.2.0.1-ee' ...
Sending build context to Docker daemon 3.454GBStep 1/22 :
FROM oraclelinux:7-slim as base
7-slim: Pulling from library/oraclelinuxStep 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/oracleORACLE_HOME=/opt/oracle/product/12.2.0.1/dbhome_1INSTALL_DIR=/opt/installINSTALL_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:$PATHLD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/libCLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlibStep 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 koracle-database-server-12cR2-preinstallx86_64 1.0-5.el7 ol7_latest 19 k
Installing for dependencies:GeoIP x86_64 1.5.0-14.el7 ol7_latest 1.5 Macl x86_64 2.2.51-15.el7 ol7_latest 81 kbc x86_64 1.06.95-13.el7 ol7_latest 114 kbind-libs x86_64 32:9.11.4-26.P2.el7_9.15 ol7_latest 158 kbind-libs-lite x86_64 32:9.11.4-26.P2.el7_9.15 ol7_latest 1.1 Mbind-license noarch 32:9.11.4-26.P2.el7_9.15 ol7_latest 91 kbind-utils x86_64 32:9.11.4-26.P2.el7_9.15 ol7_latest 261 kbinutils x86_64 2.27-44.base.0.3.el7_9.1 ol7_latest 5.4 Mcompat-libcap1 x86_64 1.10-7.el7 ol7_latest 17 kcompat-libstdc++-33 x86_64 3.2.3-72.el7 ol7_latest 190 kcracklib x86_64 2.9.0-11.el7 ol7_latest 79 kcracklib-dicts x86_64 2.9.0-11.el7 ol7_latest 3.6 Mcronie x86_64 1.4.11-25.el7_9 ol7_latest 92 kcronie-anacron x86_64 1.4.11-25.el7_9 ol7_latest 36 kcrontabs noarch 1.11-6.20121102git.el7 ol7_latest 12 kcryptsetup-libs x86_64 2.0.3-6.el7 ol7_latest 338 kdbus x86_64 1:1.10.24-15.0.1.el7 ol7_latest 245 kdbus-libs x86_64 1:1.10.24-15.0.1.el7 ol7_latest 169 kdevice-mapper x86_64 7:1.02.170-6.0.5.el7_9.5 ol7_latest 297 kdevice-mapper-libs x86_64 7:1.02.170-6.0.5.el7_9.5 ol7_latest 325 kdracut x86_64 033-572.0.13.el7 ol7_latest 331 ke2fsprogs-libs x86_64 1.42.9-19.0.1.el7 ol7_latest 168 kelfutils-default-yama-scope noarch 0.176-5.el7 ol7_latest 32 kelfutils-libs x86_64 0.176-5.el7 ol7_latest 290 kethtool x86_64 2:4.8-10.el7 ol7_latest 126 kfipscheck x86_64 1.4.1-6.el7 ol7_latest 21 kfipscheck-lib x86_64 1.4.1-6.el7 ol7_latest 10 kgeoipupdate x86_64 2.5.0-2.el7 ol7_latest 34 kglibc-devel x86_64 2.17-326.0.9.el7_9 ol7_latest 1.1 Mglibc-headers x86_64 2.17-326.0.9.el7_9 ol7_latest 694 kgssproxy x86_64 0.7.0-30.el7_9 ol7_latest 110 kgzip x86_64 1.5-11.el7_9 ol7_latest 129 khardlink x86_64 1:1.0-19.el7 ol7_latest 14 khostname x86_64 3.13-3.el7_7.1 ol7_latest 16 kinitscripts x86_64 9.49.53-1.0.3.el7_9.1 ol7_latest 443 kiproute x86_64 4.11.0-30.el7 ol7_latest 805 kiptables x86_64 1.4.21-35.0.3.el7 ol7_latest 432 kiputils x86_64 20160308-10.el7 ol7_latest 147 kjson-c x86_64 0.11-4.el7_0 ol7_latest 30 kkernel-headers x86_64 3.10.0-1160.114.2.0.1.el7 ol7_latest 9.1 Mkeyutils x86_64 1.5.8-3.el7 ol7_latest 53 kkmod x86_64 20-28.0.3.el7 ol7_latest 125 kkmod-libs x86_64 20-28.0.3.el7 ol7_latest 53 kkpartx x86_64 0.4.9-136.0.3.el7_9 ol7_latest 81 kksh x86_64 20120801-144.0.1.el7_9 ol7_latest 882 klibICE x86_64 1.0.9-9.el7 ol7_latest 66 klibSM x86_64 1.2.2-2.el7 ol7_latest 39 klibX11 x86_64 1.6.7-5.el7_9 ol7_latest 607 klibX11-common noarch 1.6.7-5.el7_9 ol7_latest 164 klibXau x86_64 1.0.8-2.1.el7 ol7_latest 28 klibXext x86_64 1.3.3-3.el7 ol7_latest 38 klibXi x86_64 1.7.9-1.el7 ol7_latest 40 klibXinerama x86_64 1.1.3-2.1.el7 ol7_latest 13 klibXmu x86_64 1.1.2-2.el7 ol7_latest 70 klibXrandr x86_64 1.5.1-2.el7 ol7_latest 27 klibXrender x86_64 0.9.10-1.el7 ol7_latest 25 klibXt x86_64 1.1.5-3.el7 ol7_latest 172 klibXtst x86_64 1.2.3-1.el7 ol7_latest 20 klibXv x86_64 1.0.11-1.el7 ol7_latest 18 klibXxf86dga x86_64 1.1.4-2.1.el7 ol7_latest 18 klibXxf86misc x86_64 1.0.3-7.1.el7 ol7_latest 19 klibXxf86vm x86_64 1.1.4-1.el7 ol7_latest 17 klibaio x86_64 0.3.109-13.el7 ol7_latest 24 klibaio-devel x86_64 0.3.109-13.el7 ol7_latest 12 klibbasicobjects x86_64 0.1.1-32.el7 ol7_latest 25 klibcollection x86_64 0.7.0-32.el7 ol7_latest 41 klibdmx x86_64 1.1.3-3.el7 ol7_latest 15 klibedit x86_64 3.0-12.20121213cvs.el7 ol7_latest 88 klibevent x86_64 2.0.21-4.el7 ol7_latest 208 klibini_config x86_64 1.3.1-32.el7 ol7_latest 63 klibmnl x86_64 1.0.3-7.el7 ol7_latest 22 klibnetfilter_conntrack x86_64 1.0.6-1.el7_3 ol7_latest 55 klibnfnetlink x86_64 1.0.1-4.el7 ol7_latest 25 klibnfsidmap x86_64 0.25-19.el7 ol7_latest 49 klibpath_utils x86_64 0.2.1-32.el7 ol7_latest 28 klibpwquality x86_64 1.2.3-5.el7 ol7_latest 84 klibref_array x86_64 0.1.5-32.el7 ol7_latest 27 klibsmartcols x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 143 klibstdc++-devel x86_64 4.8.5-44.0.3.el7 ol7_latest 1.5 Mlibtirpc x86_64 0.2.4-0.16.el7 ol7_latest 89 klibuser x86_64 0.60-9.el7 ol7_latest 400 klibutempter x86_64 1.1.6-4.el7 ol7_latest 24 klibverto-libevent x86_64 0.2.5-4.el7 ol7_latest 8.2 klibxcb x86_64 1.13-1.el7 ol7_latest 213 klm_sensors-libs x86_64 3.4.0-8.20160601gitf9185e5.0.1.el7_9.1ol7_latest 42 klz4 x86_64 1.8.3-1.el7 ol7_latest 84 kmailx x86_64 12.5-19.el7 ol7_latest 244 kmake x86_64 1:3.82-24.el7 ol7_latest 420 knet-tools x86_64 2.0-0.25.20131004git.el7 ol7_latest 305 knfs-utils x86_64 1:1.3.0-0.68.0.1.el7.2 ol7_latest 413 kopenssh x86_64 7.4p1-23.0.3.el7_9 ol7_latest 485 kopenssh-clients x86_64 7.4p1-23.0.3.el7_9 ol7_latest 655 kpam x86_64 1.1.8-23.el7 ol7_latest 720 kpkgconfig x86_64 1:0.27.1-4.el7 ol7_latest 53 kprocps-ng x86_64 3.3.10-28.0.1.el7 ol7_latest 291 kpsmisc x86_64 22.20-17.el7 ol7_latest 141 kqrencode-libs x86_64 3.4.1-3.el7 ol7_latest 49 kquota x86_64 1:4.01-19.el7 ol7_latest 178 kquota-nls noarch 1:4.01-19.el7 ol7_latest 90 krpcbind x86_64 0.2.0-49.el7 ol7_latest 59 ksmartmontools x86_64 1:7.0-2.el7 ol7_latest 546 ksysstat x86_64 10.1.5-20.0.3.el7_9 ol7_latest 316 ksystemd x86_64 219-78.0.13.el7_9.9 ol7_latest 5.1 Msystemd-libs x86_64 219-78.0.13.el7_9.9 ol7_latest 421 ksystemd-sysv x86_64 219-78.0.13.el7_9.9 ol7_latest 99 ksysvinit-tools x86_64 2.88-14.dsf.el7 ol7_latest 62 ktar x86_64 2:1.26-35.el7 ol7_latest 845 ktcp_wrappers x86_64 7.6-77.el7 ol7_latest 78 ktcp_wrappers-libs x86_64 7.6-77.el7 ol7_latest 65 kunzip x86_64 6.0-24.0.1.el7_9 ol7_latest 172 kutil-linux x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 2.0 Mxorg-x11-utils x86_64 7.5-23.el7 ol7_latest 114 kxorg-x11-xauth x86_64 1:1.0.9-1.el7 ol7_latest 29 kxz 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 Mglibc-common x86_64 2.17-326.0.9.el7_9 ol7_latest 12 Mlibblkid x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 183 klibcom_err x86_64 1.42.9-19.0.1.el7 ol7_latest 42 klibmount x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 185 klibuuid x86_64 2.23.2-65.0.4.el7_9.1 ol7_latest 84 kopenssl-libs x86_64 1:1.0.2k-26.el7_9 ol7_latest 1.2 Mxz-libs x86_64 5.2.2-2.el7_9 ol7_latest 103 kTransaction 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 builderStep 9/22 :ARG DB_EDITIONStep 10/22 :RUN yum -y install unzipStep 11/22 :COPY --chown=oracle:dba $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_DB_BINARIES_FILE $INSTALL_DIR/Step 12/22 :USER oracleStep 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 baseStep 15/22 :USER oracleStep 16/22 :COPY --chown=oracle:dba --from=builder $ORACLE_BASE $ORACLE_BASEStep 17/22 :USER rootStep 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 oracleStep 20/22 :WORKDIR /home/oracleStep 21/22 :HEALTHCHECK --interval=1m --start-period=5m CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1Step 22/22 :CMD exec $ORACLE_BASE/$RUN_FILE
Successfully built 358073b899d3
Successfully tagged oracle/database:12.2.0.1-eeOracle Database container image for 'ee' version 12.2.0.1 is ready to be extended: --> oracle/database:12.2.0.1-eeBuild 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 pdbsCON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 PDB READ WRITE NO
5.3查看当前连接的库
SQL> SQL> show con_nameCON_NAME
------------------------------
CDB$ROOT
5.4切换当前库
SQL> alter session set container=pdb;
Session altered.
5.5关闭
SQL> shutdown immediate;