编程知识 cdmana.com

Docker compose to install Oracle_ 11g_ R2 and data persistence

1, use docker-compose install

1, Create related files

mkdir /usr/local/docker
cd /usr/local/docker
mkdir oracle
cd oracle
touch docker-compose.yml 

2,docker-compose.yml The contents of the configuration file are as follows

version: '3.1'
services:
  master:
    image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
    container_name: oracle
    privileged: true
    ports:
      - 1521:1521

3, Start the container , And into the container

docker-compose up -d
docker exec -it oracle bash

4, Configuration environment , And create a user , Implement external connections

cd /home/oracle                                           #  Enter into  oracle  User directory 
source .bash_profile                                      #  load  oracle  environment variable 
$PATH                                                     #  see  oracle  Is the environment variable effective 
sqlplus / as sysdba                                       #  Connect  oracle  database 
alter user system identified by oracle;                   #  modify  DBA  Password of account 
alter user sys identified by oracle;                      #  modify  DBA  Password of account 
alter profile default limit password_life_time unlimited; #  Set the password to never expire 
create user test identified by oracle;                    #  Create a  test  user , password  oracle
select * from dba_users t where t.username = 'TEST';      #  Query whether the user is created successfully 
grant connect, resource to test;                          #  Give users access to connections and data 

5, Related configuration ( Omission )

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;          --  See if... Is enabled  true  To start 
alter system set deferred_segment_creation=false;  --  Change to not enable 
show parameter deferred_segment_creation;          --  Check whether the modification is successful  false  not enabled 

6, Use plsql Connect

  1. account number :test
  2. password :oracle
  3. Connect :ip:1521/helowin

2, Data persistence

1, You can find ,helowin An instance of is installed in :/home/oracle/app/oracle/oradata/helowin Under the table of contents

2, Copy data locally , And modify the owner

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  It's in the container  oracle  Combined users  id

3, Closed container :docker-compose down

4, Restart the container , And in docker-composr.yml Add data volume configuration

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

5, View startup log :docker logs -f oracle, We found a mistake , This is because oracle For data security , Added version validation

6, Enter the container , Solve mistakes

docker exec -it oracle bash
cd /home/oracle              #  Enter into  oracle  User directory 
source .bash_profile         #  load  oracle  environment variable ( Every time you enter the container, you have to load the configuration file )

#  Delete the newly generated version control file , Copy the version control file in the data volume to the newly generated version control file 
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          #  With  dba  Identity connection  oracle  database 
shutdown immediate           #  Close database instance ( There will be an error , Never mind )
startup                      #  Boot instance 

7, Again using plsql Connect , Create before you discover test Users can connect to , Data persistence completed successfully

PS, mirrored root User account password :root/helowin

版权声明
本文为[xxjin]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224170445560m.html

Scroll to Top