docker 安装 oracle19c

docker 安装

[root@localhost ~]# yum install docker
[root@localhost ~]# docker version
[root@localhost ~]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@localhost ~]# chkconfig docker on
Note: Forwarding request to 'systemctl enable docker.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl enable docker.service

选择 oracle 镜像

[root@laptop-6cfrmtbs ~]# docker search Oracle
INDEX       NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/oraclelinux                       Official Docker builds of Oracle Linux.         954       [OK]   
docker.io   docker.io/oracleinanutshell/oracle-xe-11g                                                   247  
docker.io   docker.io/gvenzl/oracle-xe                  Oracle Database XE (21c, 18c, 11g) for eve...   140  
docker.io   docker.io/wnameless/oracle-xe-11g-r2        Oracle Express Edition 11g Release 2 on Ub...   91   
docker.io   docker.io/truevoly/oracle-12c               Copy of sath89/oracle-12c image (https://g...   48   
docker.io   docker.io/quillbuilduser/oracle-18-xe       Oracle 18c XE Image for Quill Testing Purp...   27   
docker.io   docker.io/oracledb19c/oracle.19.3.0-ee                                                      20   
docker.io   docker.io/iamseth/oracledb_exporter         A Prometheus exporter for Oracle modeled a...   5  
docker.io   docker.io/oraclecoherence/coherence-ce      Coherence Community Edition                     5  
docker.io   docker.io/18fgsa/oracle-client              Hosted version of the Oracle Container Ima...   2  
docker.io   docker.io/kasmweb/oracle-8-desktop          Oracle Linux 8 desktop for Kasm Workspaces      2  
docker.io   docker.io/dokken/oraclelinux-7              Oracle Linux 7 image for kitchen-dokken         1  
#### 拉取oracle镜像
[root@laptop-6cfrmtbs ~]# docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle
[root@laptop-6cfrmtbs data_temp]# docker images
REPOSITORY                                          TAG                 IMAGE ID            CREATED             SIZE
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle   19c                 7b5eb4597688        2 years ago         6.61 GB

创建数据目录

[root@laptop-6cfrmtbs ~]# mkdir -p /data/oracle19/data_temp && chmod 777 /data/oracle19/data_temp

启动镜像

[root@laptop-6cfrmtbs ~]# docker run -d -it --name oracle19c -p 1521:1521 -p 5500:5500 -e ORACLE_SID=orcl -e ORACLE_PDB=orclPDB -e ORACLE_PWD=123456 -e ORACLE_EDITION=standard -e ORACLE_CHARACTERSET=AL32UTF8 -v /data/oracle19/data_temp:/opt/myData/oracle/oracleData registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle
f3c47f17c05bd340f72b3f6f0b997c22bff13128fa33522e445c84012c617469
[root@laptop-6cfrmtbs ~]# docker logs -f f3c47f17c05bd340f72b3f6f0b997c22bff13128fa33522e445c84012c617469
Database not initialized. Initializing database.
Starting tnslsnr
Copying database files
1% complete
3% complete
11% complete
[root@laptop-6cfrmtbs data_temp]# docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                       PORTS                                            NAMES
e6deffd605e3        registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle   "/bin/sh -c 'exec ..."   About an hour ago   Up About an hour (healthy)   0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   oracle19c

在容器中修改数据

[root@laptop-6cfrmtbs ~]# docker exec -it e6deffd605e3 sh
# sqlplus system/123456@//localhost:1521/orcl

SQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 23 20:55:45 2022

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL> alter user SYSTEM identified by 123456;

User altered.
[oracle@e6deffd605e3 ~]$  sqlplus system/123456@//localhost:1521/orcl

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 25 03:51:40 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Last Successful login time: Sun Dec 25 2022 03:42:03 +00:00

Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select name,cdb from v$database;

NAME      CDB
--------- ---
ORCL      YES

SQL> create user c##ruibo identified by 123456;

User created.

SQL> grant connect,resource to c##ruibo;

Grant succeeded.

SQL> grant dba,connect,resource,create view to c##ruibo;

Grant succeeded.

SQL> grant create session to c##ruibo;

Grant succeeded.

SQL> grant select any table to c##ruibo;

Grant succeeded.

SQL> grant update any table to c##ruibo;

Grant succeeded.

SQL> grant insert any table to c##ruibo;

Grant succeeded.

SQL> grant delete any table to c##ruibo;

Grant succeeded.

重启后启动容器

[root@laptop-6cfrmtbs data_temp]# docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                       PORTS                                            NAMES
e6deffd605e3        registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle   "/bin/sh -c 'exec ..."   About an hour ago   Up About an hour (healthy)   0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   oracle19c

[root@192 ~]# docker start e6deffd605e3
e6deffd605e3

访问

图片.png
图片.png

页面访问

图片.png

问题

ORA-28040 没有匹配的验证协议
图片.png
$ORACLE_HOME/network/admin/sqlnet.ora文件中添加:

[oracle@34bb81c90d7e admin]$ vim sqlnet.ora 
[oracle@34bb81c90d7e admin]$ pwd
/opt/oracle/product/19c/dbhome_1/network/admin

SQLNET.ALLOWED_LOGON_VERSION_SERVER=10
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10

exp 导出数据

[oracle@e6deffd605e3 ~]$ sqlplus sys/srmdb@localhost:1521/SRM as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 25 09:08:04 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Last Successful login time: Sun Dec 25 2022 07:13:22 +00:00
Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> create directory srm_back as '/home/rebo/srm_back';
Directory created.
SQL> grant read,write on directory srm_back to ruibo;
Grant succeeded.
[oracle@e6deffd605e3 ~]$ exp ruibo/kQtqg7GMMujmNujJqCYauzWs5cX9tg@localhost/SRM file=/home/rebo/srm_back/srm20221225

imp 导入数据

创建目录
[oracle@e6deffd605e3 ~]$ sqlplus system/123456@localhost:1521/orcl as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 25 09:08:04 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Last Successful login time: Sun Dec 25 2022 07:13:22 +00:00
Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> create directory srm_back as '/home/oracle/srm_back/';
Directory created.
SQL> grant read,write on directory srm_back to c##ruibo;
Grant succeeded.
复制导入文件到容器指定目录
[root@192 opt]# docker cp ./srm20221225.dmp e6deffd605e3:/home/oracle/srm_back
导入
[oracle@e6deffd605e3 srm_back]$ imp c##ruibo/123456@localhost/orcl file=/home/oracle/srm_back/srm20221225.dmp full=y

expdp 导出数据

[oracle@e6deffd605e3 ~]$ sqlplus sys/srmdb@localhost:1521/SRM as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 25 09:08:04 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Last Successful login time: Sun Dec 25 2022 07:13:22 +00:00
Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> create directory srm_back as '/home/rebo/srm_back';
Directory created.
SQL> grant read,write on directory srm_back to ruibo;
Grant succeeded.
[oracle@e6deffd605e3 ~]$ expdp ruibo/123456@localhost/SRM directory=srm_back dumpfile=srm20221226_expdp.dmp logfile=srm20221226.log

Export: Release 19.0.0.0.0 - Production on Mon Dec 26 03:30:09 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation: nonexistent file or path [29434]
[oracle@e6deffd605e3 srm_back]$ ll
total 34952
-rw-r--r--. 1 oracle oinstall        0 Dec 25 13:18 import_sys.sql
-rw-r--r--. 1 oracle oinstall        0 Dec 26 03:27 srm20221226_expdp.dmp
-rw-r--r--. 1 oracle oinstall        0 Dec 26 03:29 srm20221226.log
[oracle@e6deffd605e3 ~]$  sqlplus system/123456@//localhost:1521/orcl
SQL> select * from dba_directories;
SQL> create or replace directory srm_back as '/home/oracle/srm_back';
SQL> grant read,write on directory srm_back to c##ruibo;

[oracle@e6deffd605e3 srm_back]$ expdp c##ruibo/123456@localhost/orcl directory=srm_back dumpfile=srm20221226.dmp logfile=srm20221226.log

[oracle@e6deffd605e3 srm_back]$ pwd
/home/oracle/srm_back
[oracle@e6deffd605e3 srm_back]$ ll
total 34952
-rw-r--r--. 1 oracle oinstall        0 Dec 25 13:18 import_sys.sql
-rw-r--r--. 1 root   root     35790848 Dec 25 11:28 srm20221225.dmp
-rw-r--r--. 1 oracle oinstall        0 Dec 26 03:27 srm20221226.dmp
-rw-r--r--. 1 oracle oinstall        0 Dec 26 03:29 srm20221226.log

impdp 导入数据

[root@192 opt]# docker cp ./srm20221226_expdp.dmp e6deffd605e3:/home/oracle/srm_back
[oracle@e6deffd605e3 srm_back]$  impdp c##ruibo/123456@localhost/orcl directory=srm_back file=srm20221226_expdp.dmp full=y log=impdp.log remap_schema=RUIBO:C##RUIBO remap_tablespace=RUIBO:RUIBO_DATA
导入日志
[root@192 opt]# docker cp 34bb81c90d7e:/home/oracle/srm_back/impdp.log /opt/
[root@192 opt]# ls
impdp.log  srm20221225.dmp  srm20221226_expdp.dmp

表空间

[oracle@34bb81c90d7e ~]$ sqlplus system/123456@//localhost:1521/orcl

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Dec 27 07:14:51 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Last Successful login time: Tue Dec 27 2022 07:13:23 +00:00

Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> create tablespace RUIBO_DATA datafile '/opt/oracle/oradata/ORCL/RUIBO_DATA.dbf' size 4096M autoextend on next 128M maxsize 8000M;

Tablespace created.
SQL> select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;

TABLESPACE_NAME                SUM(BYTES)/1024/1024
------------------------------ --------------------
SYSTEM                                          890
UNDOTBS1                                        270
SYSAUX                                          530
USERS                                        136.25
RUIBO_DATA                                     4096