目录
一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
二、创建容器并启动数据库
三、尽情使用吧
3.1 数据库使用
3.2 创建数据库(可选)
3.3 EMDC的使用
3.4 使用ssh连接到容器内
3.5 外部客户端连接容器内的数据库
一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
-
小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest -
Oracle 11g DB的地址:https://hub.docker.com/r/lhrbest/oracle_11g_ee_lhr_11.2.0.4
1# 从Docker hub下载,网络不好时,一般比较慢
2docker pull lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
3# 可以选择从阿里云下载,一般比较快
4docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
5# 从阿里云下载后可以tag成如下形式
6docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0 lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
镜像大概2.95G左右,解压后大约7.6G左右,所以请保留充足的空间。执行过程如下:
1[[email protected]~]# docker search 11.2.0.4 --no-trunc | grep -E "NAME|lhr"
2NAME DESCRIPTION STARS OFFICIAL AUTOMATED
3lhrbest/oracle_11g_ee_lhr_11.2.0.4 Oracle 11g 企业版, 11.2.0.4 ,QQ:646634621,微信公众号:DB宝,作者:小麦苗 0
4[[email protected]~]#
5[[email protected]~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
61.0: Pulling from lhrbest/oracle_11g_ee_lhr_11.2.0.4
75dd797628260: Already exists
8ea1a739ab78d: Pull complete
9593d06e585fc: Pull complete
10Digest: sha256:7a2c2bf264cc9e5b5608deb98abe388c61d8fe2c981ee3475b0d2a38bb1fd8b4
11Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
12registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
13[[email protected]~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0 lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
14[[email protected]~]# docker images | grep 11.2.0.4
15lhrbest/oracle_11g_ee_lhr_11.2.0.4 1.0 18261f9fdcf0 43 minutes ago 7.61GB
16registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4 1.0 18261f9fdcf0 43 minutes ago 7.61GB
二、创建容器并启动数据库
1 # 创建容器
2docker run -itd --name lhrora11204 -h lhrora11204 --privileged=true -p 1521:1521 -p 222:22 -p 1158:1158 lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0 init
3
4# 进入容器
5docker exec -it lhrora11204 bash
6
7# 启动数据库和监听
8su - oracle
9lsnrctl start
10sqlplus / as sysdba
11startup
12exit
13
14# 启动EM
15emctl start dbconsole
执行过程:
1[[email protected]~]# docker exec -it lhrora11204 bash
2[[email protected]/]#
3[[email protected]/]# su - oracle
4[[email protected]~]$
5[[email protected]~]$ lsnrctl start
6
7LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-JUL-2020 09:20:41
8
9Copyright (c) 1991, 2013, Oracle. All rights reserved.
10
11Starting /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr: please wait...
12
13TNSLSNR for Linux: Version 11.2.0.4.0 - Production
14System parameter file is /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
15Log messages written to /u01/app/oracle/diag/tnslsnr/lhrora11204/listener/alert/log.xml
16Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
17Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora11204)(PORT=1521)))
18
19Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
20STATUS of the LISTENER
21------------------------
22Alias LISTENER
23Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
24Start Date 24-JUL-2020 09:20:41
25Uptime 0 days 0 hr. 0 min. 0 sec
26Trace Level off
27Security ON: Local OS Authentication
28SNMP OFF
29Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
30Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora11204/listener/alert/log.xml
31Listening Endpoints Summary...
32 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
33 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora11204)(PORT=1521)))
34The listener supports no services
35The command completed successfully
36
37[oracle@lhrora11204 ~]$ sas
38
39SQL*Plus: Release 11.2.0.4.0 Production on Fri Jul 24 09:20:50 2020
40
41Copyright (c) 1982, 2013, Oracle. All rights reserved.
42
43Connected to an idle instance.
44
45SYS@LHR11G> startup
46ORACLE instance started.
47
48Total System Global Area 325685248 bytes
49Fixed Size 2252944 bytes
50Variable Size 188747632 bytes
51Database Buffers 130023424 bytes
52Redo Buffers 4661248 bytes
53Database mounted.
54Database opened.
55SYS@LHR11G>
56SYS@LHR11G> exit
57Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
58With the Partitioning, OLAP, Data Mining and Real Application Testing options
59
60[oracle@lhrora11204 ~]$ emctl status dbconsole
61Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0
62Copyright (c) 1996, 2013 Oracle Corporation. All rights reserved.
63https://lhrora11204:1158/em/console/aboutApplication
64Oracle Enterprise Manager 11g is not running.
65------------------------------------------------------------------
66Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/lhrora11204_LHR11G/sysman/log
67[oracle@lhrora11204 ~]$ emctl start dbconsole
68Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0
69Copyright (c) 1996, 2013 Oracle Corporation. All rights reserved.
70https://lhrora11204:1158/em/console/aboutApplication
71Starting Oracle Enterprise Manager 11g Database Control ...... started.
72------------------------------------------------------------------
73Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/lhrora11204_LHR11G/sysman/log
74[oracle@lhrora11204 ~]$ emctl status dbconsole
75Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0
76Copyright (c) 1996, 2013 Oracle Corporation. All rights reserved.
77https://lhrora11204:1158/em/console/aboutApplication
78Oracle Enterprise Manager 11g is running.
79------------------------------------------------------------------
80Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/lhrora11204_LHR11G/sysman/log
三、尽情使用吧
3.1 数据库使用
1[[email protected]~]$ lsnrctl status
2
3LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-JUL-2020 09:23:08
4
5Copyright (c) 1991, 2013, Oracle. All rights reserved.
6
7Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
8STATUS of the LISTENER
9------------------------
10Alias LISTENER
11Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
12Start Date 24-JUL-2020 09:20:41
13Uptime 0 days 0 hr. 2 min. 26 sec
14Trace Level off
15Security ON: Local OS Authentication
16SNMP OFF
17Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
18Listener Log File /u01/app/oracle/diag/tnslsnr/lhrora11204/listener/alert/log.xml
19Listening Endpoints Summary...
20 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
21 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora11204)(PORT=1521)))
22Services Summary...
23Service "LHR11G" has 1 instance(s).
24 Instance "LHR11G", status READY, has 1 handler(s) for this service...
25Service "LHR11GXDB" has 1 instance(s).
26 Instance "LHR11G", status READY, has 1 handler(s) for this service...
27The command completed successfully
28[[email protected]~]$ sas
29
30SQL*Plus: Release 11.2.0.4.0 Production on Fri Jul 24 09:23:10 2020
31
32Copyright (c) 1982, 2013, Oracle. All rights reserved.
33
34
35Connected to:
36Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
37With the Partitioning, OLAP, Data Mining and Real Application Testing options
38
39[email protected]> select * from v$version;
40
41BANNER
42----------------------------------------------------------------------------------------------------------------------------------------------------------------
43Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
44PL/SQL Release 11.2.0.4.0 - Production
45CORE 11.2.0.4.0 Production
46TNS for Linux: Version 11.2.0.4.0 - Production
47NLSRTL Version 11.2.0.4.0 - Production
48
49[email protected]> select * from v$tablespace;
50
51 TS# NAME INCLUD BIGFIL FLASHB ENCRYP
52---------- ------------------------------------------------------------ ------ ------ ------ ------
53 0 SYSTEM YES NO YES
54 1 SYSAUX YES NO YES
55 2 UNDOTBS1 YES NO YES
56 4 USERS YES NO YES
57 3 TEMP NO NO YES
58 6 EXAMPLE YES NO YES
59
606 rows selected.
61
62[email protected]>
3.2 创建数据库(可选)
我们也可以自己创建自己需要的数据库,如下所示,
1dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname LHR11G2 -sid LHR11G2 \
3-sysPassword lhr -systemPassword lhr \
4-datafileDestination '/u01/app/oracle/oradata' \
5-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
6-storageType FS \
7-characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \
8-sampleSchema true \
9-totalMemory 300 \
10-databaseType OLTP \
11-emConfiguration NONE
3.3 EMDC的使用
该镜像已经创建好了EMDC (Enterprise Manager Database Control) 了, 所以,可以直接访问,地址为:https://192.168.1.36:1158/em ,sys用户密码为lhr
3.4 使用ssh连接到容器内
1C:\Users\lhrxxt>ssh root@192.168.1.36 -p222
2The authenticity of host '[192.168.1.36]:222 ([192.168.1.36]:222)' can't be established.
3RSA key fingerprint is SHA256:KCuMsxiuP493oXTYB6R3VNl2BXBEl9Hf9EYtmsAjOEE.
4Are you sure you want to continue connecting (yes/no)? yes
5Warning: Permanently added '[192.168.1.36]:222' (RSA) to the list of known hosts.
6root@192.168.1.36's password:
7Last login: Mon Jul 13 02:59:40 2020 from 172.17.0.1
8[[email protected]~]# ps -ef|grep pmon
9oracle 1574 0 0 09:20 ? 00:00:00 ora_pmon_LHR11G
10root 3882 3856 0 09:28 pts/3 00:00:00 grep pmon
3.5 外部客户端连接容器内的数据库
我们可以在容器外部通过sqlplus或其他工具连接容器内的数据库:
1C:\Users\lhrxxt>sqlplus sys/lhr@192.168.1.36/LHR11G AS SYSDBA
2
3SQL*Plus: Release 12.1.0.2.0 Production on Fri Jul 24 17:29:46 2020
4
5Copyright (c) 1982, 2014, Oracle. All rights reserved.
6
7
8Connected to:
9Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
10With the Partitioning, OLAP, Data Mining and Real Application Testing options
11
12SYS@192.168.1.36/LHR11G>
如果使用PLSQL Developer也是可以连接的,如下: