目录
在Docker中快速使用各个版本的Oracle数据库(10g、11g、12c、18c、19c、21c、23c)
oracle 10g
1、拉取镜像
docker pull registry.cn-shanghai.aliyuncs.com/techerwang/oracle:ora10g_10205
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_10g_ee_lhr_10.2.0.5:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_10g_ee_lhr_10.2.0.1:2.0
2、重新tag镜像
docker tag registry.cn-shanghai.aliyuncs.com/techerwang/oracle:ora10g_10205 oracle10g:10205
3、启动容器
docker run -itd --name oracle10g -h jemora10g \
--privileged=true \
--restart=always \
-p 3389:3389 \
-p 1521:1521 \
-p 312:22 \
oracle10g:10205 init
docker run -itd --name oracle10g -h lhrora10g \
--privileged=true \
--restart=always \
-p 3389:3389 \
-p 1521:1521 \
-p 212:22 \ --privileged=true
\ lhrbest/oracle_10g_ee_lhr_10.2.0.5:2.0 init
4、进入容器
docker exec -it oracle10 /bin/bash
5、修改 oracle 相关配置
# 启动数据库
lsnrctl start
# 连接 oracle
sql
startup
# 修改 system 密码
SQL> alter user system identified by 密码;
# 或者可以创建新用户并授权
SQL> create user test identified by “123456”;
SQL> grant connect,resource,dba to test;
# 退出连接
quit
# 设置开机启动数据库
vim /etc/rc.d/rc.local
#新增下面两行并保存:
su - oracle -c "lsnrctl start"
su - oracle -c "dbstart"
vim /etc/oratab
将 N 修改为 Y
# 退出容器
exit
# 配置完成
oracle11g
1、拉取镜像
docker pull registry.aliyuncs.com/helowin/oracle_11g
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.3:2.0
2、创建数据目录并设置权限
mkdir -p /mydata/oracle11g/app
mkdir -p /mydata/oracle11g/dpdump
mkdir -p /mydata/oracle11g/oraInventory
chmod 777 /mydata/oracle11g
3、启动容器
docker run -itd --name oracle11g \
--privileged=true \
--restart=always \
-p 1521:1521 \
-v /mydata/oracle11g/app:/opt/oracle/app \
-v /mydata/oracle11g/dpdump:/opt/oracle/dpdump \
-v /mydata/oracle11g/oraInventory:/opt/oracle/oraInventory registry.aliyuncs.com/helowin/oracle_11g
docker run -itd --name oracle11g -h lhrora11204 \
--privileged=true \
--restart=always \
-p 3389:3389 \
-p 1521:1521 \
-p 1158:1158 \
-p 224:22 \
lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0 init
4、进入容器
docker exec -it oracle11g /bin/bash
5、修改 oracle 相关配置
# 切换root,密码helowin
su root
# 切换oracle
su - oracle
# 使用 sqlplus 连接数据库
sqlplus /nolog
# 使用sysdba连接
SQL> conn /as sysdba;
# 修改 system 密码
alter user system identified by 123456;
# 修改密码有效期
alter profile default limit PASSWORD_LIFE_TIME UNLIMITED;
# 查看当前用户
show user;
# 退出 sqlplus
exit
# 查看数据库服务状态
lsnrctl status
#退出容器
exit
#配置完成
oracle12c
1、拉取镜像
docker pull docker.io/truevoly/oracle-12c
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:2.0
docker pull absolutapps/oracle-12c-ee
docker pull heidaodageshiwo/oracle-12c-ee
2、创建数据目录并设置权限
mkdir -p /mydata/oracle12g/oracle_data
mkdir -p /mydata/oracle12g/ora_data
chmod 777 /mydata/oracle12g
3、启动容器
docker run -d --name oracle12c \
--privileged=true \
--restart=always \
-p 18080:8080 \
-p 1521:1521 \
-v /mydata/oracle12g/data_temp:/home/oracle/data_temp \
-v /mydata/oracle12g/ora_data:/u01/app/oracle/
-v /etc/localtime:/etc/localtime:ro \
truevoly/oracle-12c
docker run -itd --name oracle12c -h lhrora1221 \
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 5500:5500 \
-p 5501:5501 \
-p 5522:22 \
-p 3389:3389 \
-v /mydata/oracle12g/data_temp:/home/oracle/data_temp \
-v /mydata/oracle12g/ora_data:/u01/app/oracle/
lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:2.0 init
docker run -d --name oracle12c \
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 18080:8080 \
-v /mydata/oracle12g/data_temp:/home/oracle/data_temp \
/mydata/oracle12g/ora_data:/u01/app/oracle/ \
absolutapps/oracle-12c-ee
4、进入容器
docker exec -it oracle12c /bin/bash
5、修改 oracle 相关配置
# 连接数据库,用户密码:system/oracle@
sqlplus
# 修改 system 密码
ALTER USER system IDENTIFIED BY 123456;
# 退出 sqlplus
exit
# 退出容器
exit
# 配置完成
oracle18c
1、拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/zhengqing/oracle18c
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle18clhr_rpm_db
2、启动容器
mkdir -p /mydata/oracle18c/oradata
chmod 777 /mydata/oracle18c
docker run -d --name oracle18c \
--privileged=true \
--restart=always \
-p 1521:1521 \
-v /mydata/oracle18c/oradata:/opt/oracle \
registry.cn-hangzhou.aliyuncs.com/zhengqing/oracle18c
docker run -itd -h oracle18c --name lhrora18c \
--privileged=true \
--restart=always \
-p 222:22 \
-p 1521:1521 \
-p 5500:5500 \
-v /mydata/oracle18c/oradata:/opt/oracle \
lhrbest/oracle18clhr_rpm_db /usr/sbin/init
3、进入容器
docker exec -it oracle18c /bin/bash
4、用户密码和环境变量设置
# 安装目录执行脚本,设置密码(修改的管理员密码)
./setPassword.sh 123456
# 查看 SID
grep $ORACLE_HOME /etc/oratab | cut -d: -f1
# 引入临时 SID 变量
export ORACLE_SID=ORCLCDB
# 登录ORA
sqlplus / as sysdba
# 查看所有的 PDB 数据库
show pdbs;
# 每次登录都要设置 ORACLE_SID 环境变量,
# 可以将这个写到~/.bashrc文件里去 ,执行如下命令
# 该命令在当前SQL窗口中执行即可
host echo "export ORACLE_SID=ORCLCDB" >> ~/.bashrc
# 退出sql窗口
quit
# 修改 listener.ora 文件
echo USE_SID_AS_SERVICE_LISTENER = ON >> /opt/oracle/oradata/dbconfig/ORCLCDB/listener.ora
# 退出容器
exit
# 配置完成
oracle19c
1、拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle19clhr_asm_db_12.2.0.3:2.0
2、创建数据目录并设置权限
mkdir -p /mydata/oracle19c/oradata
chmod 777 /mydata/oracle19c
3、启动容器
docker run -itd --name oracle19c \
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 5500:5500 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=orclPDB1 \
-e ORACLE_PWD=123456 \
-e ORACLE_EDITION=standard \
-e ORACLE_CHARACTERSET=UTF8 \
-e TZ=Asia/Chongqing
-v /mydata/oracle19c/oradata:/opt/oracle/oradata \
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
# 19c rpm方式安装
docker run -itd -h oracle19c --name lhrora19c \
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 5500:5500 \
-p 5501:5501 \
-p 229:22 \
-p 3389:3389 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=orclPDB1 \
-e ORACLE_PWD=123456 \
-e ORACLE_EDITION=standard \
-e ORACLE_CHARACTERSET=UTF8 \
-e TZ=Asia/Chongqing
-v /mydata/oracle19c/oradata:/opt/oracle/oradata \
lhrbest/oracle19clhr_rpm_db_12.2.0.3:2.0 init
4、进入容器
docker exec -it oracle19c /bin/bash
5、修改 oracle 相关配置
[oracle@5c028e4b2a36 ~]$ sqlplus / as sysdba
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORACLEPDB READ WRITE NO
# 修改 system 密码
SQL> alter user system identified by system;
# 修改密码不过期
SQL> alter profile default limit password_life_time unlimited;
# 设置当前实例
SQL> alter session set container=ORACLEPDB;
# 创建表空间
SQL> create tablespace skzbtest datafile '/opt/oracle/oradata/ORACLEDB/ORACLEPDB/skzbtest.dbf' size 500M autoextend on maxsize unlimited;
# 创建用户
SQL> SQL> create user skzb identified by skzb123 default tablespace skzbtest;
# 授权
SQL> grant dba to skzb;
# 配置完成
oracle21c
1、拉取镜像
# 登录仓库
docker login https://container-registry.oracle.com/
docker pull container-registry.oracle.com/database/express:21.3.0-xe
访问https://container-registry.oracle.com/,登录后点击同意《Oracle 标准条款和限制》;
# 然后在容器环境下执行
docker login container-registry.oracle.com
# 执行
docker pull container-registry.oracle.com/database/enterprise:21.3.0.0
docker pull lhrbest/oracle21c_ee_db_21.3.0.0
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle21c_ee_db_21.3.0.0
2、创建数据目录并设置权限
mkdir -p /mydata/oracle21c/cgroup
mkdir -p /mydata/oracle21c/oradata
chmod 777 /mydata/oracle21c
3、启动容器
docker run -it -d --name oracle21c -h oracle21c\
--privileged=true \
--restart=always \
-p 1525:1521 \
-p 5500:5500 \
-p 5501:5501 \
-p 3389:3389 \
-e ORACLE_PWD=123456 \
-e ORACLE_CHARACTERSET=UTF8 \
-e TZ="Asia/Shanghai" \
-v /mydata/oracle21c/oradata:/opt/oracle/oradata \
-v /mydata/oracle21c/cgroup :/sys/fs/cgroup \
lhrbest/oracle21c_ee_db_21.3.0.0 \
/usr/sbin/init
docker run -d --name oracle21c \
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 5500:5500 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=orclpdb \
-e ORACLE_PWD=123456 \
-e ORACLE_EDITION=ee \
-e ORACLE_CHARACTERSET=UTF8 \
-e TZ="Asia/Shanghai" \
-e ENABLE_ARCHIVELOG=false \
-v /mydata/oracle21c/oradata:/opt/oracle/oradata \
-v /mydata/oracle21c/cgroup :/sys/fs/cgroup \
container-registry.oracle.com/database/enterprise
docker run -d \
--privileged=true \
--restart=always \
--name oracle21c \
-p 1521:1521 \
-p 5500:5500 \
-e ORACLE_PWD=123456 \
-e ORACLE_CHARACTERSET=UTF8 \
-e TZ="Asia/Shanghai" \
-v /mydata/oracle21c/oradata:/opt/oracle/oradata \
-v /mydata/oracle21c/cgroup :/sys/fs/cgroup \
container-registry.oracle.com/database/express:21.3.0-xe
# 修改密码
# docker exec <容器名> ./setPassword.sh <新密码>
docker exec oracle ./setPassword.sh 12345
4、进入容器
docker exec -it oracle21c /bin/bash
5、修改 oracle 相关配置
# 连接数据库
sqlplus / as sysdba
# 修改 system 密码
alter user system identified by 123456;
# 退出 sqlplus
exit
# 退出容器
exit
# 配置完成
oracle23c 免费开发者版本
1、拉取镜像
# 登录仓库
docker login https://container-registry.oracle.com/
docker pull container-registry.oracle.com/database/express:21.3.0-xe
2、创建数据目录并设置权限
mkdir -p /mydata/oracle23c/cgroup
mkdir -p /mydata/oracle23c/oradata
chmod 777 /mydata/oracle23c
3、启动容器
docker run -itd --name oracle23c -h oracle23c
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 3389:3389 \
-e ORACLE_PWD=123456 \
-e ORACLE_CHARACTERSET=UTF8 \
-e TZ="Asia/Shanghai" \
-v /mydata/oracle21c/oradata:/opt/oracle/oradata \
-v /mydata/oracle21c/cgroup :/sys/fs/cgroup \
lhrbest/oracle23cfree:1.0 \
\ /usr/sbin/init
常用 sql 语句
# 查看实例名称
SELECT NAME FROM V$INSTANCE;
# 查看所有数据库
SELECT NAME FROM V$DATABASE;
# 查看版本信息
SELECT * FROM V$VERSION;
# 查看表空间
SELECT TABLESPACE_NAME,FILE_NAME,BYTES/1024/1024 AS SIZE_MB FROM DBA_DATA_FILES;
# 查看用户信息
SELECT USERNAME,ACCOUNT_STATUS FROM DBA_USERS;
# 查看表信息
SELECT TABLE_NAME,NUM_ROWS,LAST_ANALYZED FROM USER_TABLES;
标签:--,com,oracle,1521,mydata,Oracle,Docker,安装,docker
From: https://www.cnblogs.com/TMesh/p/18676326