docker安装oracle11gR2

这里给出两种方式,第一种是直接使用别人已经安装并配置好oracle的镜像,第二种是已经写好安装脚本,只需指定安装包目录就能得到oracle容器。

一、第一种

1、拉取镜像

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

该镜像由阿里云提供,比较大,可能需要下载一会,等待下载即可。

2、运行容器

1
2
3
4
#通过镜像运行容器
$ docker run -d -p 1521:1521 --name oracle registry.aliyuncs.com/helowin/oracle_11g
#检查容器是否运行成功
$ docker ps

3、配置oracle

3.1 配置环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#进入容器
$ docker exec -it oracle bash

#切换到root用户,密码是helowin
$ su root

$ vi /etc/profile
#在文件的末尾添加以下内容
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH

# 刷新配置文件,使得环境变量生效
$ source /etc/profile

#创建软连接
$ ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

3.2 创建或修改oracle用户密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#从root用户切换到oracle用户
$ su oracle
#使用sysdba 连接oracle
$ sqlplus /nolog
SQL> conn /as sysdba
#创建qcmoke用户,密码123456
SQL> create user qcmoke identified by 123456;
SQL> grant connect,resource to qcmoke;
SQL> commit;

#修改system的密码为system
SQL> alter user system identified by system;
#修改sys的密码为sys
SQL> alter user sys identified by sys;
#退出orcle
SQL> exit

4、客户端登陆

oracle客户端配置(假设oracle服务端ip为qcmoke.site):

1
2
3
4
5
6
7
8
9
helowin =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = qcmoke.site)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = helowin)
)
)

连接服务名:helowin
账号:system,密码:system
或者
账号:qcmoke,密码:123456

springboot配置

1
2
3
4
5
6
7
8
spring:
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:@qcmoke.site:1521:helowin
username: system
password: system
#username: qcmoke
#password: 123456

二、第二种

1. 下载安装包

安装包下载地址:https://www.oracle.com/database/technologies/112010-linx8664soft.html

下载两个oracle安装包:linux.x64_11gR2_database_1of2.zip 和 linux.x64_11gR2_database_2of2.zip

💁‍♂温馨提示:

如果官方下载地址失效,可到本人网盘下载:

链接:https://pan.baidu.com/s/1YwFRecm1_O3pA5efxak7iw
提取码:e5rj

2. 运行容器

1
2
3
4
#解压安装包到/install目录
$ mkdir /install/ && unzip ~/linux.x64_11gR2_database_1of2.zip -d /install/ && unzip ~/linux.x64_11gR2_database_2of2.zip -d /install/
#拉去并运行容器
$ docker run --privileged --name oracle11g -p 1522:1521 -v /install:/install jaspeen/oracle-11g

3. 创建或修改oracle用户密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#进入oracle11g容器
$ docker exec -it oracle11g /bin/bash
#切换到image的oracle用户
$ su - oracle
#进入oracle数据库
$ sqlplus / as sysdba
#创建qcmoke用户,密码123456
SQL> create user qcmoke identified by 123456;
SQL> grant connect,resource to qcmoke;
SQL> commit;

#解锁scott用户
SQL> alter user scott account unlock;
User altered.
SQL> commit;
Commit complete.
SQL> conn scott/tiger
ERROR:
ORA-28001: the password has expired
Changing password for scott
#输入tiger即可
New password:
#在此输入tiger即可
Retype new password:
Password changed
Connected.
SQL>

4. 客户端登录

oracle客户端配置(假设oracle服务端ip为39.108.102.215):

1
2
3
4
5
6
7
8
9
orcl =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 39.108.102.215)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)

连接服务名:orcl
账号:scott,密码:tiger
或者
账号:qcmoke,密码:123456

springboot配置

1
2
3
4
5
6
7
8
spring:
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:@39.108.102.215:1522:orcl
username: scott
password: tiger
#username: qcmoke
#password: 123456

参考:

https://www.jianshu.com/p/4ede7dcc1d86

https://hub.docker.com/r/jaspeen/oracle-11g



----------- 本文结束 -----------




如果你觉得我的文章对你有帮助,你可以打赏我哦~
0%