1、采用 docker-compose 安装
mkdir -p /data/oracle
cd /data/oracle
vim docker-compose.yml
2,docker-compose.yml 配置文件的内容如下
version: '3.1'
services:
master:
image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
container_name: oracle
privileged: true
ports:
- 1521:1521
docker-compose up -d
docker exec -it oracle bash
镜像的 root 密码是 helowin
每次进入 oracle 容器都要加载环境变量
cd /home/oracle
source .bash_profile
sqlplus / as sysdba
创建一个用户实现在外部使用 PLSQL 连接
修改DBA账号的密码、设置密码永不过期,创建test用户,给用户授权连接
alter user system identified by system;
alter user sys identified by sys;
alter profile default limit password_life_time unlimited;
create user test identified by test;
select * from dba_users t where t.username = 'test';
grant connect, resource to test
grant dba to test;
grant select on V_$session to test;
grant select on V_$sesstat to test;
grant select on V_$statname to test;
show parameter deferred_segment_creation; -- 查看是否启用 true 为启动
alter system set deferred_segment_creation=false; -- 修改为不启用
show parameter deferred_segment_creation; -- 查看是否修改成功 false 未
启用
之后就可以使用PLSQL连接了
账号密码: test
连接: IP地址:1521/helowin
连接类型: noromal
2,数据持久化
1. 在 容 器 中 查 看 表 空 间 , 数 据 库 实 例 helowin 的 表 空 间 安 装
在/home/oracle/app/oracle/oradata/helowin目录下;
2. 复制数据到本地,并修改拥有者;
docker cp oracle:/home/oracle/app/oracle/oradata/helowin /data/oracle/helowin
cd /data/oracle
chown -R 500.500 ./helowin # 500 500 是容器内 oracle 组合用户的 id
3. 关闭容器,修改 docker-composr.yml 配置文件后启动容器;
version: '3.1'
services:
master:
image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
container_name: oracle
privileged: true
ports:
- 1521:1521
volumes:
- ./helowin:/home/oracle/app/oracle/oradata/helowin
4. docker logs -f oracle 查看启动日志发现一个报错,是因为oracle为了数据安全添加
了版本验证,可以进入容器解决

进入容器,加载环境变量
docker exec -it oracle bash
cd /home/oracle
source .bash_profile
# 删除新生成的版本控制文件,将数据卷中的版本控制文件复制为新生成的版本控制文件
rm -rf /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl
cp /home/oracle/app/oracle/oradata/helowin/control01.ctl
/home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl
进入数据库,重启实例
sqlplus / as sysdba
shutdown immediate
startup
7,再次使用 plsql 连接,发现之前创建 test 用户可以连接,数据持久化顺利完成
PS,镜像的 root 用户账号密码:root/helowin
本文详细指导如何使用docker-compose安装Oracle 11g,包括设置环境变量、创建用户、数据持久化以及解决版本验证问题。重点介绍了如何配置容器、数据迁移和解决容器启动错误。

2071

被折叠的 条评论
为什么被折叠?



