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
cd /home/oracle # 进入到 oracle 用户目录 source .bash_profile # 加载 oracle 环境变量 $PATH # 查看 oracle 环境变量是否生效 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; # 给用户授予连接和数据权限
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 未启用
oracle_11g = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.168.1.***)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = helowin) ) )
docker cp oracle:/home/oracle/app/oracle/oradata/helowin /usr/local/docker/oracle/helowin cd /usr/local/docker/oracle chown -R 500.500 ./helowin # 500 500 是容器内 oracle 组合用户的 id
docker-compose down
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
/home/oracle/app/oracle/product/11.2.0/dbhome_2 Processing Database instance "helowin": log file /home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log Redo Buffers 24137728 bytes ORA-00214: control file '/home/oracle/app/oracle/oradata/helowin/control01.ctl' version 877 inconsistent with file '/home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl' version 841 SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options /home/oracle/app/oracle/product/11.2.0/dbhome_2/bin/dbstart: Database instance "helowin" warm started.
docker exec -it oracle bash cd /home/oracle # 进入到 oracle 用户目录 source .bash_profile # 加载 oracle 环境变量(每次进入容器都要加载配置文件) # 删除新生成的版本控制文件,将数据卷中的版本控制文件复制为新生成的版本控制文件 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 # 启动实例