注意:docker启动oracle后执行systemctl enable docker.service开启持久化

  1. 需要挂载目录的要写到/etc/fstab来配置开机自启
  2. 需要自启的脚本命令写到/etc/rc.local来配置开机自启

1、拉取镜像

  1. docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

2、启动一个临时容器,获取初始化数据

  1. docker run -d --name test --restart unless-stopped \
  2. -p 1521:1521 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
  3. mkdir -p /var/oracle11/data
  4. docker cp test:/home/oracle/app/oracle/oradata/helowin /var/oracle11/data
  5. cd /var/oracle11/data
  6. chown -R 777 helowin

3、启动容器

  1. docker rm -f test
  2. docker run -d --name oracle11g --restart unless-stopped \
  3. -v /var/oracle11/data/helowin:/home/oracle/app/oracle/oradata/helowin \
  4. -p 1521:1521 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

4、初始化数据库

  1. docker exec -it oracle11g bash
  2. cd /home/oracle/
  3. source .bash_profile
  4. sqlplus / as sysdba # 连接 oracle 数据库
  5. alter user system identified by oracle; # 修改 DBA 账号的密码
  6. alter user sys identified by oracle; # 修改 DBA 账号的密码
  7. alter profile default limit password_life_time unlimited; # 设置密码为永不过期
  8. create user test identified by oracle; # 创建一个 test 用户,密码 oracle
  9. select * from dba_users t where t.username = 'TEST'; # 查询用户是否创建成功
  10. grant connect, resource to test; # 给用户授予连接和数据权限
  11. select name from v$database; # 查询当前oracle的实例名

5、解决“ORA-01109: database not open”报错的问题

image.png

  1. rm -rf /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl
  2. cp /home/oracle/app/oracle/oradata/helowin/control01.ctl /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl
  3. sqlplus / as sysdba # 以 dba 身份连接 oracle 数据库
  4. shutdown immediate # 关闭数据库实例(这里会报错,不用管)
  5. startup # 启动实例