原 【DB宝10】在Docker中只需2步即可拥有Oracle 18c环境
Tags: Oracle原创LinuxDocker安装部署小麦苗环境搭建快速体验OCP体验
一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
- 小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest
- Oracle 18c DB的地址:https://hub.docker.com/r/lhrbest/oracle18clhr_rpm_db/tags
1 2 3 4 5 6 | # 从Docker hub下载,网络不好时,一般比较慢 docker pull lhrbest/oracle18clhr_rpm_db # 可以选择从阿里云下载 docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db # 从阿里云下载后可以tag成如下形式 docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db lhrbest/oracle18clhr_rpm_db |
镜像大概5G左右,解压后大约13G左右,所以请保留充足的空间。执行过程如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@docker35 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db Using default tag: latest latest: Pulling from lhrbest/oracle18clhr_rpm_db ac9208207ada: Already exists 5f7f556e707f: Pull complete Digest: sha256:e2e90034c232e328441b704a3db2edeb13a83cfe5e5dd9221f6ee954c4efdf1e Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db:latest registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db:latest [root@docker35 ~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db lhrbest/oracle18clhr_rpm_db [root@docker35 ~]# docker images | grep 18c lhrbest/oracle18clhr_rpm_db latest d99be9a3f472 11 days ago 13.1GB registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db latest d99be9a3f472 11 days ago 13.1GB [root@docker35 ~]# |
二、创建容器并启动数据库
1 2 3 4 5 6 | # 1、创建容器 docker run -itd -h lhr18cocp --name lhr18cocp -p 222:22 -p 1522:1521 -p 5500:5500 --privileged=true lhrbest/oracle18clhr_rpm_db /usr/sbin/init # 2、进入容器 docker exec -it lhr18cocp bash # 3、启动监听和数据库,使用root命令一键启动 /etc/init.d/oracledb_ORCLCDB-18c start |
在创建容器时,需要注意端口映射关系。在以上命令中,主机的222、1521和5500这3个端口不能被占用,否则会创建失败。
如果想再创建一个容器,那么只需要将以上命令修改参数name和p不同即可,立马就可以拥有一个新的环境,而且和之前的IP地址不同,用来做测试再方便不过了,如下:
1 2 3 4 5 6 | # 1、创建容器2 docker run -itd -h lhr18cocp --name lhr18cocp2 -p 223:22 -p 1523:1521 -p 5501:5500 --privileged=true lhrbest/oracle18clhr_rpm_db /usr/sbin/init # 2、进入容器2 docker exec -it lhr18cocp2 bash # 3、启动监听和数据库,使用root命令一键启动 /etc/init.d/oracledb_ORCLCDB-18c start |
执行过程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [root@docker35 ~]# docker images | grep 18c lhrbest/oracle18clhr_rpm_db latest d99be9a3f472 11 days ago 13.1GB registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db latest d99be9a3f472 11 days ago 13.1GB [root@docker35 ~]# docker run -itd -h lhr18cocp --name lhr18cocp -p 222:22 -p 1522:1521 -p 5500:5500 --privileged=true lhrbest/oracle18clhr_rpm_db /usr/sbin/init 4bf134861d2c67faf68b1a8c42beb66821abc0fa2fc49a34beb143d218f00657 [root@docker35 ~]# docker exec -it lhr18cocp bash [root@lhr18crpm /]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@lhr18cocp /]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.8 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:08 txqueuelen 0 (Ethernet) RX packets 672 bytes 101230 (98.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 593 bytes 3748736 (3.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lhr18cocp /]# /etc/init.d/oracledb_ORCLCDB-18c start Starting Oracle Net Listener. Oracle Net Listener started. Starting Oracle Database instance ORCLCDB. Oracle Database instance ORCLCDB started. [root@lhr18crpm /]# su - oracle Last login: Sun Jun 28 14:05:18 CST 2020 on pts/0 [oracle@lhr18crpm ~]$ echo $ORACLE_HOME /opt/oracle/product/18c/dbhome_1 [oracle@lhr18crpm ~]$ echo $ORACLE_SID ORCLCDB |
再创建一个新的容器,可以看到IP地址和之前的不同,容器和容器之间是互不影响的,用来做cdb和pdb的迁移再好不过了:
1 2 3 4 5 6 7 8 9 10 11 | [root@docker35 ~]# docker run -itd -h lhr18cocp --name lhr18cocp2 -p 223:22 -p 1523:1521 -p 5501:5500 --privileged=true lhrbest/oracle18clhr_rpm_db /usr/sbin/init 68a14533f2024f33400c37ba0056456834db17ac1d6af62b05464016b137bdcc [root@docker35 ~]# docker exec -it lhr18cocp2 bash [root@lhr18cocp /]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.9 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:09 txqueuelen 0 (Ethernet) RX packets 8 bytes 656 (656.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
三、尽情使用吧
3.1 数据库使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | [root@lhr18cocp /]# su - oracle Last login: Thu Jul 9 16:57:52 CST 2020 on pts/1 [oracle@lhr18cocp ~]$ lsnrctl status LSNRCTL for Linux: Version 18.0.0.0.0 - Production on 09-JUL-2020 17:02:23 Copyright (c) 1991, 2018, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhr18cocp)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 18.0.0.0.0 - Production Start Date 09-JUL-2020 16:57:52 Uptime 0 days 0 hr. 4 min. 31 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /opt/oracle/product/18c/dbhome_1/network/admin/listener.ora Listener Log File /opt/oracle/diag/tnslsnr/lhr18cocp/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhr18cocp)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhr18cocp)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/product/18c/dbhome_1/admin/ORCLCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW)) Services Summary... Service "ORCLCDB" has 1 instance(s). Instance "ORCLCDB", status READY, has 1 handler(s) for this service... Service "ORCLCDBXDB" has 1 instance(s). Instance "ORCLCDB", status READY, has 1 handler(s) for this service... Service "a8cb5bdeb697291fe0530f0011acfe5a" has 1 instance(s). Instance "ORCLCDB", status READY, has 1 handler(s) for this service... Service "orclpdb1" has 1 instance(s). Instance "ORCLCDB", status READY, has 1 handler(s) for this service... The command completed successfully [oracle@lhr18cocp ~]$ sas SQL*Plus: Release 18.0.0.0.0 - Production on Thu Jul 9 17:01:30 2020 Version 18.3.0.0.0 Copyright (c) 1982, 2018, Oracle. All rights reserved. Connected to: Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production Version 18.3.0.0.0 SYS@ORCLCDB> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 READ WRITE NO |
可以,不错