基于Docker安装Oracle11g
-
-
- 拉取镜像
- 以持久化的方式启动容器
- 修改配置文件
- 创建软连接
- 连接Oracle
- 修改相关信息
- 修改SID
-
- 修改oracle用户的环境变量
- 修改/etc/oratab文件
- [进入ORACLE_HOME/dbs目录,修改文件名](#进入ORACLE_HOME/dbs目录,修改文件名)
- 启动数据库,检查SID
- 连接Oracle
-
拉取镜像
bash
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
docker images

以持久化的方式启动容器
bash
mkdir -p /home/data/oracle/app/oracle/oradata
docker run -d -p 1521:1521 --name oracle11g --restart=always \
--mount source=oracle_vol,target=/home/data/oracle/app/oracle/oradata \
registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
docker ps

关于持久化,source=oracle_vol指的是容器中的数据卷路径,target指的是容器外需要被挂载的目录路径。
查看volume的具体位置
bash
docker volume inspect oracle_vol

修改配置文件
bash
docker exec -it -u root oracle11g /bin/bash
vi /etc/profile

使用I键进入编辑模式,添加以下配置信息,再使用Esc键退出编辑模式,输入:wq保存配置信息。
bash
# oracle home目录
export ORACLE_HOME=/home/oracle/app/oracle/prouct/11.2.0/dbhome_2
# oracle 服务名或者SID名
export ORACLE_SID=helowin
# oracle 环境变量
export PATH=$ORACLE_HOME/bin:$PATH
# 字符集和中文乱码问题
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
检查配置信息是否保存成功
bash
cat /etc/profile

加载配置文件
bash
source /etc/profile
创建软连接
bash
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
连接Oracle
bash
# 切换用户
su - oracle
# 登录Oracle
sqlplus /nolog
# 连接Oracle
conn /as sysdba

修改相关信息
sql
# 修改system用户的密码为system
alter user system identified by system;
# 修改sys用户的密码为sys
alter user sys identified by sys;
# 修改密码规则策略为密码永不过期
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

修改SID
查看原镜像中设置的SID
sql
select instance from v$thread;

bash
# 关闭数据库
shutdown immediate
# 退出sqlplus
exit

修改oracle用户的环境变量
bash
vi /home/oracle/.bash_profile

bash
cat /home/oracle/.bash_profile

bash
source /home/oracle/.bash_profile
修改/etc/oratab文件
bash
vi /etc/oratab

进入$ORACLE_HOME/dbs目录,修改文件名
bash
cd $ORACLE_HOME/dbs
mv hc_helowin.dat hc_honey.dat
mv lkHELOWIN lkhoney
mv orapwhelowin orapwhoney
mv spfilehelowin.ora spfilehoney.ora
mv inithelowin.ora inithoney.ora
启动数据库,检查SID
sql
sqlplus / as sysdba
# 启动数据库
startup
# 检查SID
select instance from v$thread;

连接Oracle
