docker安装oracle

docker安装oracle

1、安装docker环境。

2、开始拉取oracle镜像

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

3、下载完成后,查看镜像

1
docker images

4、创建容器

1
docker run -d -p 1521:1521 --name oracle11g registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

可以写成shell脚本,下次打开oracle数据库就可以一条命令创建容器。

shell脚本如下:

1
2
3
4
5
6
7
8
9
# BEGIN ANSIBLE MANAGED BLOCK
#!/bin/bash
docker rm -f oracle11;
docker run -it -d -p 1521:1521
--privileged=true \
-v /opt/oracle/oradata/dbs:/home/oracle/app/oracle/product/11.2.0/dbhome_2/dbs \
-v /opt/oracle/oradata:/home/oracle/app/oracle/oradata \
-e ORACLE_PWD=helowin --name oracle11 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
# END ANSIBLE MANAGED BLOCK

但为了保存上一次容易的配置值,是不建议写这个shell脚本的,下次打开直接用docker start oracle11命令打开。

如果创建成功能会返回容器id

5、进入镜像进行配置

1
docker exec -it oracle11 bash

6、进行sql登录

1
sqlplus /nolog

发现没有该命令,需要先配置环境变量,所以切换root用户。

1
su root 

输入密码:helowin

7、编辑profile文件配置ORACLE环境变量

打开: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

8、保存后执行source /etc/profile 加载环境变量;

9、创建软连接

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

10、切换到oracle 用户

1
su - oracle

这里还要说一下,一定要写中间的短横线 - 必须要,否则软连接无效

11、登录sqlplus并修改sys、system用户密码

1
2
3
4
5
6
7
8
sqlplus /nolog   --登录
conn /as sysdba --
alter user system identified by system;--修改system用户账号密码;
alter user sys identified by system;--修改sys用户账号密码;
create user test identified by test; -- 创建内部管理员账号密码;
grant connect,resource,dba to yan_test; --将dba权限授权给内部管理员账号和密码;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; --修改密码规则策略为密码永不过期;(会出现坑,后面讲解)
alter system set processes=1000 scope=spfile; --修改数据库最大连接数据;

12、修改以上信息后,需要重新启动数据库;

1
2
3
4
conn /as sysdba
shutdown immediate; --关闭数据库
startup; --启动数据库
exit:退出软链接

*上面提到的其中一个坑说明:*

当执行修改密码的时候出现 : database not open

提示数据库没有打开,不急按如下操作

输入:

1
alter database open;

注意了:这里也许还会提示 : ORA-01507: database not mounted

解决办法:

输入:

1
alter database mount;

输入 :alter database open;

然后就可执行 修改数据库密码的命令了

改完之后输入:

1
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

刷新下表 exit 是退出sql 软连接

13、复制oracle的数据及配置

1
sudo docker cp id:/home/oracle/app/oracle /opt/oracle