# 从Docker hub下载,网络不好时,一般比较慢
docker pull lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
# 推荐从阿里云下载
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
# 从阿里云下载后可以tag成如下形式
docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
镜像大概4.05G左右,解压后大约16G左右,所以请保留充足的空间。执行过程如下:
[root@lhrdocker ~]# docker search 12cR1 --no-trunc
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
lhrbest/oracle_12cr1_ee_lhr_12.1.0.2 Oracle 12cR1 企业版, 12.1.0.2 ,QQ:646634621,微信公众号:DB宝,CentOS 7.6,包含一个cdb,sid为lhrcdb1,一个非cdb,sid为lhrsdb 0
[root@lhrdocker ~]#
[root@lhrdocker ~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
1.0: Pulling from lhrbest/oracle_12cr1_ee_lhr_12.1.0.2
ac9208207ada: Already exists
3f87d8dbb1ef: Pull complete
512a15c4c83e: Pull complete
0602305ad716: Pull complete
Digest: sha256:99ef263a861f71c7bac56018fad58b61640e40a44e98f0e9bd135a077a07960e
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
[root@lhrdocker ~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
[root@lhrdocker ~]# docker images | grep 12.1
lhrbest/oracle_12cr1_ee_lhr_12.1.0.2 1.0 2d8e7a9451ec 28 hours ago 15.9GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2 1.0 2d8e7a9451ec 28 hours ago 15.9GB
# 创建镜像
docker run -itd --name lhrora1212 -h lhrora1212 --privileged=true -p 1522:1521 -p 223:22 -p 5550:5500 -p 5551:5501 lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 init
# 进入容器
docker exec -it lhrora1212 bash
# 启动数据库和监听
su - oracle
lsnrctl start
sqlplus / as sysdba
startup
exit
ORACLE_SID=lhrsdb
sas
startup
运行过程:
[root@lhrdocker ~]# docker run -itd --name lhrora1212 -h lhrora1212 --privileged=true -p 1522:1521 -p 223:22 -p 5550:5500 -p 5551:5501 lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 init
b9896808a05e6d755d67e4c35159a39ab538fb6dde2af50c5e4a45a01b50b0cc
[root@lhrdocker ~]# docker exec -it lhrora1212 bash
[root@lhrora1212 /]# su - oracle
Last login: Fri Jul 10 18:15:13 CST 2020 on pts/2
[oracle@lhrora1212 ~]$ lsnrctl start
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-JUL-2020 22:52:39
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Starting /u01/app/oracle/product/12.1.0.2/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.1.0.2.0 - Production
System parameter file is /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1212)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 11-JUL-2020 22:52:39
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[oracle@lhrora1212 ~]$ sas
SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 22:52:42 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SYS@lhrcdb1> startup
ORACLE instance started.
Total System Global Area 805306368 bytes
Fixed Size 2929552 bytes
Variable Size 377490544 bytes
Database Buffers 419430400 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SYS@lhrcdb1> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 LHRPDB1 READ WRITE NO
SYS@lhrcdb1> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@lhrora1212 ~]$ ORACLE_SID=lhrsdb
[oracle@lhrora1212 ~]$ sas
SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 22:53:51 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SYS@lhrsdb> startup
ORACLE instance started.
Total System Global Area 805306368 bytes
Fixed Size 2929552 bytes
Variable Size 373296240 bytes
Database Buffers 423624704 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SYS@lhrsdb> show pdbs
SYS@lhrsdb> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
该镜像包括一个cdb(sid为lhrcdb1)和一个非cdb(sid为lhrsdb),可以直接使用:
[oracle@lhrora1212 ~]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-JUL-2020 22:56:29
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1212)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 11-JUL-2020 22:52:39
Uptime 0 days 0 hr. 3 min. 49 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "lhrcdb1" has 1 instance(s).
Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrcdb1XDB" has 1 instance(s).
Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrpdb1" has 1 instance(s).
Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrsdb" has 1 instance(s).
Instance "lhrsdb", status READY, has 1 handler(s) for this service...
Service "lhrsdbXDB" has 1 instance(s).
Instance "lhrsdb", status READY, has 1 handler(s) for this service...
The command completed successfully
我们也可以自己创建自己需要的数据库,如下所示:
# 静默创建一个cdb的库
dbca -silent -ignorePreReqs -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
-gdbname lhrcdb1 -sid lhrcdb1 \
-createAsContainerDatabase TRUE \
-numberOfPDBs 1 \
-pdbName lhrpdb1 \
-pdbAdminPassword lhr \
-sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
-datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
-storageType FS \
-characterset AL32UTF8 \
-sampleSchema true \
-totalMemory 1024 \
-databaseType MULTIPURPOSE \
-emConfiguration NONE
# 静默创建一个非cdb的库
dbca -silent -ignorePreReqs -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
-gdbname lhrsdb -sid lhrsdb \
-createAsContainerDatabase FALSE \
-sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
-datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
-storageType FS \
-characterset ZHS16GBK \
-sampleSchema true \
-totalMemory 1024 \
-databaseType MULTIPURPOSE \
-emConfiguration NONE
该镜像已经配置好EMDE(Enterprise Manager Database Express)了,可以直接使用,端口号分别为5500和5501,5500端口为cdb的em端口号,5501为非cdb的em端口号,但是我们在创建容器的时候进行了端口映射,所以访问EM时需要注意端口的不同:
[oracle@lhrora1212 ~]$ lsnrctl status | grep tcps
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
C:\Users\lhrxxt>ssh root@192.168.59.220 -p223
The authenticity of host '[192.168.59.220]:223 ([192.168.59.220]:223)' can't be established.
ECDSA key fingerprint is SHA256:ccSyRCHeeBDxZ29MPE47TA+c+d875ldU4PyM6Avv7vw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.59.220]:223' (ECDSA) to the list of known hosts.
root@192.168.59.220's password:
[root@lhrora1212 ~]# ps -ef|grep pmon
oracle 210 0 0 22:52 ? 00:00:00 ora_pmon_lhrcdb1
oracle 656 0 0 22:53 ? 00:00:00 ora_pmon_lhrsdb
root 1733 1705 0 22:59 pts/2 00:00:00 grep --color=auto pmon
在连接时,需要注意端口映射的不同,主机的1522映射为容器内的1521端口:
C:\Users\lhrxxt>sqlplus sys/lhr@192.168.59.220:1522/lhrcdb1 as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 23:00:13 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@192.168.59.220:1522/lhrcdb1> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 LHRPDB1 READ WRITE NO
SYS@192.168.59.220:1522/lhrcdb1> conn sys/lhr@192.168.59.220:1522/lhrsdb as sysdba
Connected.
SYS@192.168.59.220:1522/lhrsdb> show pdbs
如果使用PLSQL Developer也是可以连接的,如下:
怎么样,是不是很爽,是不是非常方便呢,文末记得点赞哈。
本文结束。