一、安装oracle19c
1、拉取镜像
docker pull /zhuyijun/oracle:19c
2、启动容器
-
docker run -p 1521:1521 -p 5500:5500 \
-
--name oracle1 \
-
--net=host \
-
-e ORACLE_SID=orcl \
-
-e ORACLE_PDB=orclpdb1 \
-
-e ORACLE_PWD=123456 \
-
-e ORACLE_CHARACTERSET=zhs16gbk \
-
-e ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 \
-
-e PATH=/opt/oracle/product/19c/dbhome_1/bin:/opt/oracle/product/19c/dbhome_1/OPatch/:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
-
-v /data/oracle/oradata:/opt/oracle/oradata \
-
/zhuyijun/oracle:19c
注意:其中/data/oracle/oradata是宿主机上的挂载路径。
如果启动失败,会显示
这个时候就要分析原因。我是因为忘记给挂载的目录赋予写权限,导致一直失败。这个地方要注意。
# 记得给挂载路径赋予权限
chmod -R a+x+w+r /data/oracle/oradata
如果启动失败,会留下容器进程,而且容器名字不能重复,可以用这个命令批量删除启动失败的进程。
docker rm $(docker ps -a | grep oracle | awk '{print $1}')
成功输出:
3、这时先不要关闭终端,另外开启一个终端,进入环境修改oracle密码
docker exec oracle1 ./ 123456
修改完密码后可以关闭之前终端了,出现 DATABASE IS READY TO USE之后,后边都是显示的日志,可以关闭终端,关闭终端不会导致它停止运行。
4、进入容器
-
docker ps | grep oracle
-
5bb11ac3efc7 /zhuyijun/oracle:19c "/bin/sh -c 'exec $O…" 28 minutes ago Up 28 minutes (healthy) oracle1
-
[root@feature-platform-001 ORCL]# docker exec -it oracle1 /bin/bash
-
sh-4.2$
-
-
输入
-
sqlplus / as sysdba;
如果你使用成功,那么恭喜你。这篇文章到此为止。
然而我这里遇到些问题,startup也会报错,好像和我的某个系统参数设置有关,懒得解决了,打算换个oracle12c。
-
SQL> select * from v$log;
-
select * from v$log
-
*
-
ERROR at line 1:
-
ORA-01034: ORACLE not available
-
Process ID: 0
-
Session ID: 0 Serial number: 0
二、安装oracle12c
下载镜像
docker pull /truevoly/oracle-12c
建立挂载目录
mkdir /data/oracle/data_temp && chmod 777 /data/oracle/data_temp
运行镜像
docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /data/oracle/data_temp:/home/oracle/data_temp -v /etc/localtime:/etc/localtime:ro --name oracle12c truevoly/oracle-12c
查看日志:
-
[root@feature-platform-001 ~]# docker logs -f c81d10c1006827f4b5e0acbbba566210f5e5fa4a7d6fd7b791b1cad5d0ae8963
-
-
Database not initialized. Initializing database.
-
-
Starting tnslsnr
-
-
Copying database files
-
-
1% complete
-
-
3% complete
-
-
11% complete
-
-
18% complete
-
-
37% complete
-
-
Creating and starting Oracle instance
-
-
40% complete
-
-
45% complete
-
-
50% complete
-
-
55% complete
-
-
56% complete
-
-
60% complete
-
-
62% complete
-
-
Completing Database Creation
-
-
66% complete
-
-
70% complete
-
-
73% complete
-
-
85% complete
-
-
96% complete
-
-
100% complete
-
-
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/" for further details.
-
-
Configuring Apex console
-
-
-
-
PL/SQL procedure successfully completed.
-
-
-
-
-
-
Starting import from '/':
-
-
ls: cannot access //*: No such file or directory
-
-
Import finished
-
-
-
-
-
-
Database ready to use. Enjoy! ;)
进入容器
-
[root@feature-platform-001 ~]# docker ps | grep oracle
-
-
c81d10c10068 truevoly/oracle-12c "/ " 7 minutes ago Up 7 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:18080->8080/tcp oracle12c
-
-
-
-
[root@feature-platform-001 ~]# docker exec -it c81d10c10068 /bin/bash
-
-
-
-
root@c81d10c10068:/# sqlplus /nolog
-
-
-
-
-
-
SQL*Plus: Release 12.1.0.2.0 Production on Thu Sep 16 14:58:34 2021
-
-
-
-
-
-
Copyright (c) 1982, 2014, Oracle. All rights reserved.
-
-
-
-
-
-
SQL> connect sys as sysdba
-
-
Enter password: oracle
-
-
Connected.
-
-
SQL>
-
-
SQL> select status from v$instance;
-
-
-
-
-
-
STATUS
-
-
------------
-
-
OPEN
-
-
-
-
SQL> alter user system identified by 123456;
-
-
-
-
-
-
User altered.
创建用户
-
create user 账户 identified by 密码;
-
-
GRANT CONNECT, RESOURCE, DBA TO wcz;
查询数据库名称
-
SQL> select value from v$parameter where name='service_names';
-
-
-
-
-
-
VALUE
-
-
--------------------------------------------------------------------------------
-
-
xe
连接信息:
账号:wcz
密码:123456
端口:1521
服务名称:xe
常用操作:
-
--首先查询一下用户的profile的类型
-
-
select username ,profile from dba_users;
-
-
-
-
-
-
--查看制定概要文件(默认为DEFAULT)的密码有效期:
-
-
select * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
-
-
-
-
-
-
--然后将密码的有效期有180天设置为“无限制”;
-
-
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
-
-
-
-
-
-
-- 修改密码
-
-
alter user hysjy identified by 123456;
-
-
-
-
-
-
-- 查询所有用户
-
-
SELECT * FROM ALL_USERS;
-
-
-
-
-
-
-- 创建账户
-
-
create user hysjy identified by 123456;
-
-
GRANT CONNECT, RESOURCE, DBA TO hysjy;
-
-
-
-
-
-
-- 给用户授予权限
-
-
grant create session to hysjy;
-
-
grant connect,resource to hysjy;
-
-
-
-
-
-
-- 解除锁定
-
-
alter user hysjy account unlock;
-
-
-
-
-
-
commit;