注意:docker启动oracle后执行systemctl enable docker.service开启持久化
需要挂载目录的要写到/etc/fstab来配置开机自启
需要自启的脚本命令写到/etc/rc.local来配置开机自启
1、拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
2、启动一个临时容器,获取初始化数据
docker run -d --name test --restart unless-stopped \
-p 1521:1521 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
mkdir -p /var/oracle11/data
docker cp test:/home/oracle/app/oracle/oradata/helowin /var/oracle11/data
cd /var/oracle11/data
chown -R 777 helowin
3、启动容器
docker rm -f test
docker run -d --name oracle11g --restart unless-stopped \
-v /var/oracle11/data/helowin:/home/oracle/app/oracle/oradata/helowin \
-p 1521:1521 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
4、初始化数据库
docker exec -it oracle11g bash
cd /home/oracle/
source .bash_profile
sqlplus / as sysdba # 连接 oracle 数据库
alter user system identified by oracle; # 修改 DBA 账号的密码
alter user sys identified by oracle; # 修改 DBA 账号的密码
alter profile default limit password_life_time unlimited; # 设置密码为永不过期
create user test identified by oracle; # 创建一个 test 用户,密码 oracle
select * from dba_users t where t.username = 'TEST'; # 查询用户是否创建成功
grant connect, resource to test; # 给用户授予连接和数据权限
select name from v$database; # 查询当前oracle的实例名
5、解决“ORA-01109: database not open”报错的问题
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 # 以 dba 身份连接 oracle 数据库
shutdown immediate # 关闭数据库实例(这里会报错,不用管)
startup # 启动实例