Docker快速搭建Oracle服务,导入dmp文件

代码审计遇到oracle数据库,记录一下如何快速的搭建,然后导入dmp数据库备份文件

0x01 前置环境

  1. macos
  2. Docker

0x02 搭建Oracle服务

1、拉取Oracle镜像

1
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

2、运行镜像

1
docker run -p 1521:1521 --name oracle_11g --restart=always -v /Users/zy/Desktop/logs:/home/oracle/app/oracle/oradata/mydata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
1
2
3
4
5
6
-v /Users/zy/Desktop/logs:/home/oracle/app/oracle/oradata/mydata

前面/Users/zy/Desktop/logs 是物理机器的路径

/home/oracle/app/oracle/oradata/mydata 是docker里面的路径

image-20210304164235951

3、进入容器设置用户信息

1
docker exec -it oracle_11g bash

4、切换root用户,密码:helowin

1
2
3
[[email protected] /]$ su
Password:
[[email protected] /]#

5、配置oracle环境变量

1
vi /etc/profile

在末尾添加

1
2
3
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2 
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH

刷新配置

1
source /etc/profile

创建建立sqlplus软连接

1
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

切换到oracle用户

1
2
3
[[email protected] /]# exit
exit
[[email protected] /]$

刷新配置(如果找不到命令,就多刷新配置)

1
source /etc/profile

登录sqlplus

1
sqlplus / as sysdba  

修改sys和system用户密码

1
2
3
alter user system identified by 123456;
alter user sys identified by 123456;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

连接配置

image-20210304165951371

//创建用户、用户授权

1
2
3
4
5
//创建用户
create user test identified by 123456;
//用户授权
grant connect, resource,dba to test;

登陆测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[[email protected] /]$ sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 4 17:03:17 2021

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

Enter user-name: test
Enter password:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

0x03 数据库文件拷

从宿主机拷文件 uc.dmp到容器里面

1
docker cp /Users/zy/Desktop/dbtemp.dmp oracle_11g:/home

改一下权限

1
[[email protected] home]# chmod 777 temp.dmp

恢复数据库

1
imp test/123456 file=/home/dbtemp.dmp ignore=y full=y
1
2
3
4
imp  //是oracle自带的导入工具
test/123456 //使用的用户名密码
file=/home/dbtemp.dmp //备份文件路径
ignore=y full=y //模式