目录
一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件二、创建容器并启动数据库三、尽情使用吧3.1 数据库使用3.2 创建数据库3.3 EMDE的使用3.4 使用ssh连接到容器内3.5 外部客户端连接容器内的数据库
-
小麦苗的Docker Hub的地址:https:///u/lhrbest
-
小麦苗的Oracle 12cR2(12.2.0.1)的Docker Hub地址:https:///r/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1/tags

1# 从Docker hub下载,网络不好时,一般比较慢
2docker pull lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
3# 推荐从阿里云下载
4docker pull /lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
5# 从阿里云下载后可以tag成如下形式
6docker tag registry.cn-/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0 lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
镜像大概4.79G左右,解压后大约15G左右,所以请保留充足的空间。执行过程如下:
1[root@lhrdocker ~]# docker search 12cR2 --no-trunc
2NAME DESCRIPTION STARS OFFICIAL AUTOMATED
3lhrbest/oracle_12cr2_ee_lhr_12.2.0.1 Oracle 12cR2 企业版, 12.2.0.1 ,QQ:646634621,微信公众号:DB宝,CentOS 7.6,包含一个cdb,sid为lhrcdb1,一个非cdb,sid为lhrsdb 0
4[root@lhrdocker ~]# docker pull /lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
51.0: Pulling from lhrbest/oracle_12cr2_ee_lhr_12.2.0.1
6ac9208207ada: Already exists
73f87d8dbb1ef: Already exists
8512a15c4c83e: Already exists
9ce417a4cad38: Pull complete
10Digest: sha256:5b2924030665688c2dbd5722b0bf21fbf4fcc69efbac8f113dd43c43b6241341
11Status: Downloaded newer image for /lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
12/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
13[root@lhrdocker ~]# docker tag registry.cn-/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0 lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
14[root@lhrdocker ~]# docker images | grep 12.2
15lhrbest/oracle_12cr2_ee_lhr_12.2.0.1 1.0 c9a76e991b46 27 hours ago 14.8GB
16/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1 1.0 c9a76e991b46 27 hours ago 14.8GB
二、创建容器并启动数据库
1# 创建镜像
2docker run -itd --name lhrora1221 -h lhrora1221 --privileged=true -p 1521:1521 -p 222:22 -p 5500:5500 -p 5501:5501 lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0 init
3
4# 进入容器
5docker exec -it lhrora1221 bash
6
7# 启动数据库和监听
8su - oracle
9lsnrctl start
10sqlplus / as sysdba
11startup
12exit
13ORACLE_SID=lhrsdb
14sas
15startup
运行过程:
1[root@lhrdocker ~]# docker run -itd --name lhrora1221 -h lhrora1221 --privileged=true -p 1521:1521 -p 222:22 -p 5500:5500 -p 5501:5501 lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0 init
2e46fc8ff1a9bb4dd905d08de3515036695a8267a2e0f30b553d05dc16f38005e
3[root@lhrdocker ~]# docker exec -it lhrora1221 bash
4[root@lhrora1221 /]# su - oracle
5Last login: Fri Jul 10 16:36:50 CST 2020 on pts/0
6[oracle@lhrora1221 ~]$ lsnrctl start
7
8LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-JUL-2020 20:00:05
9
10Copyright (c) 1991, 2016, Oracle. All rights reserved.
11
12Starting /u01/app/oracle/product/12.2.0.1/dbhome_1/bin/tnslsnr: please wait...
13
14TNSLSNR for Linux: Version 12.2.0.1.0 - Production
15System parameter file is /u01/app/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
16Log messages written to /u01/app/oracle/diag/tnslsnr/lhrora1221/listener/alert/log.xml
17Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1221)(PORT=1521)))
18Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
19
20Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1221)(PORT=1521)))
21STATUS of the LISTENER
22------------------------
23Alias LISTENER
24Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
25Start Date 11-JUL-2020 20:00:05
26Uptime 0 days 0 hr. 0 min. 0 sec
27Trace Level off
28Security ON: Local OS Authentication
29SNMP OFF
30Listener Parameter File /u01/app/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
31Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora1221/listener/alert/log.xml
32Listening Endpoints Summary...
33 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1221)(PORT=1521)))
34 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
35The listener supports no services
36The command completed successfully
37[oracle@lhrora1221 ~]$ sas
38
39SQL*Plus: Release 12.2.0.1.0 Production on Sat Jul 11 20:00:17 2020
40
41Copyright (c) 1982, 2016, Oracle. All rights reserved.
42
43Connected to an idle instance.
44
45SYS@lhrcdb1> startup
46ORACLE instance started.
47
48Total System Global Area 805306368 bytes
49Fixed Size 8797928 bytes
50Variable Size 583008536 bytes
51Database Buffers 205520896 bytes
52Redo Buffers 7979008 bytes
53Database mounted.
54Database opened.
55SYS@lhrcdb1> show pdbs
56
57 CON_ID CON_NAME OPEN MODE RESTRICTED
58---------- ------------------------------ ---------- ----------
59 2 PDB$SEED READ ONLY NO
60 3 LHRPDB1 MOUNTED
61SYS@lhrcdb1> alter pluggable database lhrpdb1 open;
62
63Pluggable database altered.
64
65SYS@lhrcdb1> show pdbs
66
67 CON_ID CON_NAME OPEN MODE RESTRICTED
68---------- ------------------------------ ---------- ----------
69 2 PDB$SEED READ ONLY NO
70 3 LHRPDB1 READ WRITE NO
71SYS@lhrcdb1> alter pluggable database all save state;
72
73Pluggable database altered.
74
75SYS@lhrcdb1> exit
76Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
77[oracle@lhrora1221 ~]$ ORACLE_SID=lhrsdb
78[oracle@lhrora1221 ~]$ sas
79
80SQL*Plus: Release 12.2.0.1.0 Production on Sat Jul 11 20:02:10 2020
81
82Copyright (c) 1982, 2016, Oracle. All rights reserved.
83
84Connected to an idle instance.
85
86SYS@lhrsdb> startup
87ORACLE instance started.
88
89Total System Global Area 805306368 bytes
90Fixed Size 8625856 bytes
91Variable Size 578814272 bytes
92Database Buffers 209715200 bytes
93Redo Buffers 8151040 bytes
94Database mounted.
95Database opened.
96SYS@lhrsdb>
三、尽情使用吧
3.1 数据库使用
该镜像包括一个cdb(sid为lhrcdb1)和一个非cdb(sid为lhrsdb),可以直接使用:
1[oracle@lhrora1221 ~]$ lsnrctl status
2
3LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-JUL-2020 20:06:02
4
5Copyright (c) 1991, 2016, Oracle. All rights reserved.
6
7Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1221)(PORT=1521)))
8STATUS of the LISTENER
9------------------------
10Alias LISTENER
11Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
12Start Date 11-JUL-2020 20:00:05
13Uptime 0 days 0 hr. 5 min. 57 sec
14Trace Level off
15Security ON: Local OS Authentication
16SNMP OFF
17Listener Parameter File /u01/app/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
18Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora1221/listener/alert/log.xml
19Listening Endpoints Summary...
20 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1221)(PORT=1521)))
21 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
22 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
23 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
24Services Summary...
25Service "aa133779e7bf28e8e053090011ac3234" has 1 instance(s).
26 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
27Service "lhrcdb1" has 1 instance(s).
28 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
29Service "lhrcdb1XDB" has 1 instance(s).
30 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
31Service "lhrpdb1" has 1 instance(s).
32 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
33Service "lhrsdb" has 1 instance(s).
34 Instance "lhrsdb", status READY, has 1 handler(s) for this service...
35Service "lhrsdbXDB" has 1 instance(s).
36 Instance "lhrsdb", status READY, has 1 handler(s) for this service...
37The command completed successfully
3.2 创建数据库
我们也可以自己创建自己需要的数据库,如下所示:
1# 静默创建一个cdb的库
2dbca -silent -ignorePreReqs -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
3-gdbname lhrcdb1 -sid lhrcdb1 \
4-createAsContainerDatabase TRUE \
5-numberOfPDBs 1 \
6-pdbName lhrpdb1 \
7-pdbAdminPassword lhr \
8-sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
9-datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
10-storageType FS \
11-characterset AL32UTF8 \
12-sampleSchema true \
13-totalMemory 1024 \
14-databaseType MULTIPURPOSE \
15-emConfiguration NONE
16
17# 静默创建一个非cdb的库
18dbca -silent -ignorePreReqs -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
19-gdbname lhrsdb -sid lhrsdb \
20-createAsContainerDatabase FALSE \
21-sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
22-datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
23-storageType FS \
24-characterset ZHS16GBK \
25-sampleSchema true \
26-totalMemory 1024 \
27-databaseType MULTIPURPOSE \
28-emConfiguration NONE
3.3 EMDE的使用
该镜像已经配置好EMDE(Enterprise Manager Database Express)了,可以直接使用,端口号分别为5500和5501,5500端口为cdb的em端口号,5501为非cdb的em端口号:
-
CDB数据库lhrcdb1的EM访问地址:https://192.168.59.220:5500/em
-
非CDB数据库lhrsdb的EM访问地址:https://192.168.59.220:5501/em
1[oracle@lhrora1221 ~]$ lsnrctl status | grep tcps
2 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
3 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
4[oracle@lhrora1221 ~]$


3.4 使用ssh连接到容器内
1C:\Users\lhrxxt>ssh root@192.168.59.220 -p222
2The authenticity of host '[192.168.59.220]:222 ([192.168.59.220]:222)' can't be established.
3ECDSA key fingerprint is SHA256:ccSyRCHeeBDxZ29MPE47TA+c+d875ldU4PyM6Avv7vw.
4Are you sure you want to continue connecting (yes/no)? yes
5Warning: Permanently added '[192.168.59.220]:222' (ECDSA) to the list of known hosts.
6root@192.168.59.220's password:
7Last login: Fri Jul 10 16:23:29 2020
8[root@lhrora1221 ~]# ps -ef|grep pmon
9oracle 202 0 0 20:00 ? 00:00:00 ora_pmon_lhrcdb1
10oracle 930 0 0 20:02 ? 00:00:00 ora_pmon_lhrsdb
11root 4194 4165 0 20:24 pts/2 00:00:00 grep --color=auto pmon
12[root@lhrora1221 ~]#
3.5 外部客户端连接容器内的数据库
1C:\Users\lhrxxt>sqlplus sys/lhr@192.168.59.220:1521/lhrcdb1 as sysdba
2
3SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 20:24:46 2020
4
5Copyright (c) 1982, 2014, Oracle. All rights reserved.
6
7
8Connected to:
9Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
10
11SYS@192.168.59.220:1521/lhrcdb1> show pdbs
12
13 CON_ID CON_NAME OPEN MODE RESTRICTED
14---------- ------------------------------ ---------- ----------
15 2 PDB$SEED READ ONLY NO
16 3 LHRPDB1 READ WRITE NO
17SYS@192.168.59.220:1521/lhrcdb1> conn sys/lhr@192.168.59.220:1521/lhrsdb as sysdba
18Connected.
19SYS@192.168.59.220:1521/lhrsdb> show pdbs
20SYS@192.168.59.220:1521/lhrsdb>
如果使用PLSQL Developer也是可以连接的,如下:


怎么样,是不是很爽,是不是非常方便呢。

















