Docker容器

Docker部署Oracle 19c

本文主要是介绍Docker部署Oracle 19c,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一. 拉取Oracle 19c镜像

[root@centos ~]# docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
19c: Pulling from zhuyijun/oracle
bce8f778fef0: Pull complete 
3fc3fd32c0bc: Pull complete 
02948dd6d654: Pull complete 
67f2dfeb2f1b: Pull complete 
2e42d8039fd9: Pull complete 
b94f01bb60c6: Pull complete 
Digest: sha256:3898a9394720f30ce7f0b83ef2d172f4cd11b958282e0505f83cf2b0e5eaf7d4
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c

二. 查看镜像

[root@centos ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED         SIZE
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle   19c       7b5eb4597688   20 months ago   6.61GB
oracleinanutshell/oracle-xe-11g                     latest    ad13c30ec346   3 years ago     2.13GB

三. 创建Oracle 19c镜像的容器
3.1创建目录

mkdir /opt/oradata
chmod -R 777 /opt/oradata/

3.2 创建实例

docker run -d -it --name oracle19c -p 1521:1521 -p 5500:5500 -v /opt/oradata:/opt/oracle/oradata registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c

3.3 查看日志

[root@centos ~]# docker logs -f oracle19c
ORACLE EDITION: ENTERPRISE
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: 6EgzYeYTSok=1

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 24-APR-2022 06:11:47

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/387f010d46e9/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                24-APR-2022 06:11:47
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/387f010d46e9/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.

四、 修改密码

# 系统默认的system密码修改成oracle
docker exec oracle19c ./setPassword.sh oracle

setPassword.sh 脚本如下

[root@centos ~]# docker exec -it oracle19c /bin/bash
[oracle@centos ~]$ ls
setPassword.sh
[oracle@centos ~]$ pwd
/home/oracle
[oracle@centos ~]$ cat setPassword.sh 
#!/bin/bash
# LICENSE UPL 1.0
#
# Copyright (c) 1982-2018 Oracle and/or its affiliates. All rights reserved.
# 
# Since: November, 2016
# Author: gerald.venzl@oracle.com
# Description: Sets the password for sys, system and pdb_admin
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
# 
 
ORACLE_PWD=$1
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
ORAENV_ASK=NO
source oraenv
 
sqlplus / as sysdba << EOF
      ALTER USER SYS IDENTIFIED BY "$ORACLE_PWD";
      ALTER USER SYSTEM IDENTIFIED BY "$ORACLE_PWD";
      ALTER SESSION SET CONTAINER=$ORACLE_PDB;
      ALTER USER PDBADMIN IDENTIFIED BY "$ORACLE_PWD";
      exit;
EOF

五、连接数据库

sqlplus system/oracle@xxx.xxx.xxx.xxx:1521/ORCLCDB

5.1测试方案一:进入容器内部测试

[root@centos ~]# docker exec -it oracle19c /bin/bash
[oracle@centos ~]$ sqlplus system/oracle@localhost:1521/ORCLCDB
 
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 7 01:54:17 2022
Version 19.3.0.0.0
 
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
 
Last Successful login time: Thu Apr 07 2022 01:53:14 +00:00
 
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
 
SQL> Show user;
USER is "SYSTEM"
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@centos ~]$ 

5.2测试方案二:用navicat连接测试

[root@centos ~]# docker exec -it oracle19c /bin/bash
[oracle@centos ~]$ cd /opt/oracle/product/19c/dbhome_1/network/admin/
[oracle@centos admin]$ ls
listener.ora  samples  shrept.lst  sqlnet.ora  tnsnames.ora
[oracle@centos admin]$ vim sqlnet.ora 
[oracle@centos admin]$ cat sqlnet.ora 
NAME.DIRECTORY_PATH= (TNSNAMES, EZCONNECT, HOSTNAME)
[oracle@centos admin]$ vim sqlnet.ora 
[oracle@centos admin]$ cat sqlnet.ora 
NAME.DIRECTORY_PATH= (TNSNAMES, EZCONNECT, HOSTNAME)
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
[oracle@centos admin]$ exit
exit
[root@centos ~]# docker ps -a
CONTAINER ID   IMAGE                                                   COMMAND                  CREATED        STATUS                  PORTS                                                                                  NAMES
1249a4a7bb32   registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c   "/bin/sh -c 'exec $O…"   16 hours ago   Up 16 hours (healthy)   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 0.0.0.0:5500->5500/tcp, :::5500->5500/tcp   oracle19c
[root@centos ~]# docker restart oracle19c
oracle19c
[root@centos ~]# 
这篇关于Docker部署Oracle 19c的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!