目录
一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
二、创建容器并启动数据库
三、尽情使用吧
3.1 数据库使用
3.2 创建数据库
3.3 EMDE的使用
3.4 使用ssh连接到容器内
3.5 外部客户端连接容器内的数据库
-
小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest
-
小麦苗的Oracle 12cR1(12.1.0.2)的Docker Hub地址:https://hub.docker.com/r/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2/tags
1# 从Docker hub下载,网络不好时,一般比较慢
2docker pull lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
3# 推荐从阿里云下载
4docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
5
6# 从阿里云下载后可以tag成如下形式
7docker 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左右,所以请保留充足的空间。执行过程如下:
1[root@lhrdocker ~]# docker search 12cR1 --no-trunc
2NAME DESCRIPTION STARS OFFICIAL AUTOMATED
3lhrbest/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
4[root@lhrdocker ~]#
5[root@lhrdocker ~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
61.0: Pulling from lhrbest/oracle_12cr1_ee_lhr_12.1.0.2
7ac9208207ada: Already exists
83f87d8dbb1ef: Pull complete
9512a15c4c83e: Pull complete
100602305ad716: Pull complete
11Digest: sha256:99ef263a861f71c7bac56018fad58b61640e40a44e98f0e9bd135a077a07960e
12Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
13registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
14[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
15[root@lhrdocker ~]# docker images | grep 12.1
16lhrbest/oracle_12cr1_ee_lhr_12.1.0.2 1.0 2d8e7a9451ec 28 hours ago 15.9GB
17registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2 1.0 2d8e7a9451ec 28 hours ago 15.9GB
二、创建容器并启动数据库
1# 创建镜像
2docker 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
3
4# 进入容器
5docker exec -it lhrora1212 bash
6
7# 启动数据库和监听
8su - oracle
9lsnrctl start
10sqlplus / as sysdba
11startup
12exit
13ORACLE_SID=lhrsdb
14sas
15startup
运行过程:
1[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
2b9896808a05e6d755d67e4c35159a39ab538fb6dde2af50c5e4a45a01b50b0cc
3[root@lhrdocker ~]# docker exec -it lhrora1212 bash
4[root@lhrora1212 /]# su - oracle
5Last login: Fri Jul 10 18:15:13 CST 2020 on pts/2
6[oracle@lhrora1212 ~]$ lsnrctl start
7
8LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-JUL-2020 22:52:39
9
10Copyright (c) 1991, 2014, Oracle. All rights reserved.
11
12Starting /u01/app/oracle/product/12.1.0.2/dbhome_1/bin/tnslsnr: please wait...
13
14TNSLSNR for Linux: Version 12.1.0.2.0 - Production
15System parameter file is /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
16Log messages written to /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
17Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
18Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
19
20Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1212)(PORT=1521)))
21STATUS of the LISTENER
22------------------------
23Alias LISTENER
24Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
25Start Date 11-JUL-2020 22:52:39
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.1.0.2/dbhome_1/network/admin/listener.ora
31Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
32Listening Endpoints Summary...
33 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
34 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
35The listener supports no services
36The command completed successfully
37[oracle@lhrora1212 ~]$ sas
38
39SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 22:52:42 2020
40
41Copyright (c) 1982, 2014, 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 2929552 bytes
50Variable Size 377490544 bytes
51Database Buffers 419430400 bytes
52Redo Buffers 5455872 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 READ WRITE NO
61SYS@lhrcdb1> exit
62Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
63With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
64
65[oracle@lhrora1212 ~]$ ORACLE_SID=lhrsdb
66[oracle@lhrora1212 ~]$ sas
67
68SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 22:53:51 2020
69
70Copyright (c) 1982, 2014, Oracle. All rights reserved.
71
72Connected to an idle instance.
73
74SYS@lhrsdb> startup
75ORACLE instance started.
76
77Total System Global Area 805306368 bytes
78Fixed Size 2929552 bytes
79Variable Size 373296240 bytes
80Database Buffers 423624704 bytes
81Redo Buffers 5455872 bytes
82Database mounted.
83Database opened.
84SYS@lhrsdb> show pdbs
85SYS@lhrsdb> exit
86Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
87With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
三、尽情使用吧
3.1 数据库使用
该镜像包括一个cdb(sid为lhrcdb1)和一个非cdb(sid为lhrsdb),可以直接使用:
1[oracle@lhrora1212 ~]$ lsnrctl status
2
3LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-JUL-2020 22:56:29
4
5Copyright (c) 1991, 2014, Oracle. All rights reserved.
6
7Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1212)(PORT=1521)))
8STATUS of the LISTENER
9------------------------
10Alias LISTENER
11Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
12Start Date 11-JUL-2020 22:52:39
13Uptime 0 days 0 hr. 3 min. 49 sec
14Trace Level off
15Security ON: Local OS Authentication
16SNMP OFF
17Listener Parameter File /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
18Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
19Listening Endpoints Summary...
20 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
21 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
22 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
23 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
24Services Summary...
25Service "lhrcdb1" has 1 instance(s).
26 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
27Service "lhrcdb1XDB" has 1 instance(s).
28 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
29Service "lhrpdb1" has 1 instance(s).
30 Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
31Service "lhrsdb" has 1 instance(s).
32 Instance "lhrsdb", status READY, has 1 handler(s) for this service...
33Service "lhrsdbXDB" has 1 instance(s).
34 Instance "lhrsdb", status READY, has 1 handler(s) for this service...
35The 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端口号,但是我们在创建容器的时候进行了端口映射,所以访问EM时需要注意端口的不同:
-
CDB数据库lhrcdb1的EM访问地址:https://192.168.59.220:5550/em
-
非CDB数据库lhrsdb的EM访问地址:https://192.168.59.220:5551/em
1[oracle@lhrora1212 ~]$ lsnrctl status | grep tcps
2 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
3 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
3.4 使用ssh连接到容器内
1C:\Users\lhrxxt>ssh root@192.168.59.220 -p223
2The authenticity of host '[192.168.59.220]:223 ([192.168.59.220]:223)' 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]:223' (ECDSA) to the list of known hosts.
6root@192.168.59.220's password:
7[root@lhrora1212 ~]# ps -ef|grep pmon
8oracle 210 0 0 22:52 ? 00:00:00 ora_pmon_lhrcdb1
9oracle 656 0 0 22:53 ? 00:00:00 ora_pmon_lhrsdb
10root 1733 1705 0 22:59 pts/2 00:00:00 grep --color=auto pmon
3.5 外部客户端连接容器内的数据库
在连接时,需要注意端口映射的不同,主机的1522映射为容器内的1521端口:
1C:\Users\lhrxxt>sqlplus sys/lhr@192.168.59.220:1522/lhrcdb1 as sysdba
2
3SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 23:00:13 2020
4
5Copyright (c) 1982, 2014, Oracle. All rights reserved.
6
7
8Connected to:
9Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
10With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
11
12SYS@192.168.59.220:1522/lhrcdb1> show pdbs
13
14 CON_ID CON_NAME OPEN MODE RESTRICTED
15---------- ------------------------------ ---------- ----------
16 2 PDB$SEED READ ONLY NO
17 3 LHRPDB1 READ WRITE NO
18SYS@192.168.59.220:1522/lhrcdb1> conn sys/lhr@192.168.59.220:1522/lhrsdb as sysdba
19Connected.
20SYS@192.168.59.220:1522/lhrsdb> show pdbs
如果使用PLSQL Developer也是可以连接的,如下:
怎么样,是不是很爽,是不是非常方便呢。