查看docker版本
[root@localhost overlay2]# docker -v
Docker version 20.10.14, build a224086
搜索docker下的oracle镜像
docker search oracle 查看docker中oracle镜像

下载docker镜像
docker pull truevoly/oracle-12c

查看docker下载的镜像
docker images

创建备份数据库存放目录
mkdir /usr/local/oracle/data_temp && chmod 777 /usr/local/oracle/data_temp
创建一个文件目录,用于挂载到容器内,做oracle数据备份时数据存放的位置,保证备份数据不丢失。
启动docker下的oracle镜像
docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /usr/local/oracle/data_temp:/home/oracle/data_temp -v /etc/localtime:/etc/localtime:ro --name orac truevoly/oracle-12c

查看安装进度
docker logs -f 3c3c255029f52e009e28b1bd06f2e34a255d422c0ce6a5ad4ff0b37df8d2f18d

查看运行的容器:
[root@localhost data_temp]# docker ps

进入docker容器
docker exec -it 容器id /bin/bash
[root@localhost data_temp]# docker exec -it 3c3c255029f5 /bin/bash

进入oracle
sqlplus system/oracle@//localhost:1521/xe
使用pl/sql连接时,xe镜像默认的服务

进入数据库
sqlplus /nolog
connect sys as sysdba; #密码:oracle
查看oracle的状态,状态为OPEN则正常
select status from v$instance;
alter user system identified by oracle; ## 修改用户 system 的密码为 oracle ,可以自定义
创建账户
create user 账户 identified by 密码;
(create user tupb identified by tupb;) 创建用户名为tupb密码为tupb的账户。
GRANT CONNECT, RESOURCE, DBA TO tupb;
给用户tupb赋权
grant create session to testlu;
grant connect,resource to testlu;
查询所有账户
SELECT * FROM ALL_USERS;
使用以下命令获取安装的数据库的服务名称:
select value from v$parameter where name='service_names';
接下来就可以使用客户端连接了
账号:tupb 密码:tupb 端口: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 tupb identified by tupb;
-- 查询所有用户
SELECT * FROM ALL_USERS;
-- 创建账户
create user tupb identified by tupb;
GRANT CONNECT, RESOURCE, DBA TO tupb;
-- 给用户授予权限
grant create session to tupb;
grant connect,resource to tupb;
-- 解除锁定
alter user tupb account unlock;
commit;
网友评论