1.创建Oracle容器
docker run -itd --restart=always --name oracle11g -h lhrora11204 -p 1521:1521 --privileged=true -e TZ="Asia/Shanghai" registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0 init
2.启动oracle
2.1.启动实例
docker exec -it oracle11g bash
su oracle
source /home/oracle/.bash_profile
sqlplus "/as sysdba"
startup
2.2 修改系统账号和密码
后面连接需要用到
alter user system identified by orcl;
alter user sys identified by orcl;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
效果图
2.3 启动监听
#启动监听
lsnrctl start
2.4 连接数据库
3.创建数据库
3.1 复制一份数据库创建脚本
#复制一份文件为db_install.rsp
cp -r /u01/app/oracle/product/11.2.0.4/dbhome_1/assistants/dbca/dbca.rsp /u01/app/oracle/product/11.2.0.4/dbhome_1/assistants/dbca/db_install.rsp
#将文件复制出来修改
docker cp oracle11g:/u01/app/oracle/product/11.2.0.4/dbhome_1/assistants/dbca/db_install.rsp /home
#退出容器
exit
以下是db_install的修改内容
######## db_install.rsp ########
RESPONSEFILE_VERSION = "11.2.0.4"
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "orcl"
SYSTEMPASSWORD = "orcl"
SYSMANPASSWORD = "orcl"
DBSNMPPASSWORD = "orcl"
DATAFILEDESTINATION =/u01/app/oracle/oradata
RECOVERYAREADESTINATION=/u01/app/oracle/flash_recovery_area
CHARACTERSET = "ZHS16GBK" #CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "8192"
######## db_install.rsp ########
3.2 创建数据库
#将修改后的db_install.rsp复制到容器
docker cp /home/db_install.rsp oracle11g:/u01/app/oracle/product/11.2.0.4/dbhome_1/assistants/dbca/db_install.rsp
#创建数据库步骤
docker exec -it oracle11g bash
su - oracle
source /home/oracle/.bash_profile
dbca -silent -responseFile /u01/app/oracle/product/11.2.0.4/dbhome_1/assistants/dbca/db_install.rsp
3.3 删除初始数据库文件
cd /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs
#删除LHR11G相关文件
rm -rf snapcf_LHR11G.f spfileLHR11G.ora orapwLHR11G lkLHR11Ghc_LHR11G.dat
#删除LHR11G相关文件
rm -rf /u01/app/oracle/admin/LHR11G /u01/app/oracle/cfgtoollogs/dbca/LHR11G /u01/app/oracle/cfgtoollogs/emca/LHR11G /u01/app/oracle/diag/rdbms/lhr11g/LHR11G /u01/app/oracle/flash_recovery_area/LHR11G /u01/app/oracle/oradata/LHR11G
3.4 修改监听文件
cd /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin
cp -r listener.ora listener.ora.backup
vim listener.ora
以下是listener.ora文件内容
############################# listener.ora #############################
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = lhrora11204)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
############################# listener.ora #############################
5.自启动实例和监听
5.1 自启动实例
#重启容器
docker restart oracle11g
#重启oracle11g镜像发现,监听和实例都没启动
#进入容器将实例改为自启
docker exec -it oracle11g bash
#用root修改rc.local
vi /etc/rc.d/rc.local
#### 内容如下 ####
su - oracle -c "lsnrctl start"
su - oracle -c "dbstart"
#### 内容如下结束 ####
#实例自启,修改oratab
su oracle
vi /etc/oratab
#将N改为Y
orcl:/u01/app/oracle/product/11.2.0.4/dbhome_1:Y
5.2 自启动监听
su oracle
source /home/oracle/.bash_profile
#修改脚本,避免自启报错
vi $ORACLE_HOME/bin/dbshut
vi $ORACLE_HOME/bin/dbstart
#ORACLE_HOME_LISTNER=$1,修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
5.3 查看是否自启
docker restart oracle11g
docker logs -f oracle11g
6. 修改字符集编码(可选)
sqlplus /as sysdba
shutdown immediate;
startup mount;
#执行SQL
alter system enable restricted session;
alter system set job_queue_processes=0;
alter system set aq_tm_processes=0;
alter database open;
#修改数据库编码
ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
#重新启动数据库
shutdown immediate;
startup;
#查询字符集是否启动成功
select userenv('language') from dual;
7. 修改数据库连接(可选)
# 修改连接数(sessions=1.1*process+5)
alter system set processes = 1000 scope = spfile;
alter system set sessions=1105 scope=spfile;