欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker安装运行oracle数据库步骤

程序员文章站 2024-03-25 17:12:28
...

Docker安装运行oracle数据库步骤

1、docker拉取oracle数据库镜像

# 搜索oracle镜像
[aaa@qq.com ~]# docker search oracle --filter=STARS=17
NAME                              DESCRIPTION                                     STARS   
oraclelinux                       Official Docker builds of Oracle Linux.         652     
jaspeen/oracle-11g                Docker image for Oracle 11g database            159     
oracleinanutshell/oracle-xe-11g                                                   99
oracle/graalvm-ce                 GraalVM Community Edition Official Image        71     
truevoly/oracle-12c               Copy of sath89/oracle-12c image (https://git…   25
   

2、docker下载oracle镜像

# 我选择是第5镜像 truevoly/oracle-12c,这个镜像有点大,大概有5个多G,不过下载很快,大概5分钟
[aaa@qq.com ~]# docker pull truevoly/oracle-12c
Using default tag: latest
latest: Pulling from truevoly/oracle-12c
a3ed95caeb02: Pull complete
778e440c7584: Pull complete
d85b3b18f9f8: Pull complete
dba3a843d373: Pull complete
.
.
# 查看刚才下载的oracle镜像
[aaa@qq.com ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
truevoly/oracle-12c   latest              21789d4d876f        16 months ago       5.7GB

3、创建数据库挂载文件

将docker内的数据库文件同步到你的主机目录下,防止容器删除后数据库丢失

[aaa@qq.com ~]# mkdir -p /var/local/ora_data
[aaa@qq.com ~]# chmod -R 777 /var/local/ora_data/

4、启动镜像

[aaa@qq.com ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
truevoly/oracle-12c   latest              21789d4d876f        16 months ago       5.7GB
# docker run 运行 -V:主机目录 容器内目录
[aaa@qq.com ~]# docker run -d -p 2122:22 -p 9090:8080 -p 1521:1521 -v /var/local/ora_data:/u01/app/oracle/ --name oracle truevoly/oracle-12c
de4a43288724f36380a442a8c2ab56a36df2dd4c5b79266c4908575aacb3c590
[aaa@qq.com ~]# 启动成功

5、查看启动日志

[aaa@qq.com ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED               
6383227303cd        truevoly/oracle-12c   "/entrypoint.sh "        2 minutes ago         
# 耐心等待,第一次启动大概需要五六分钟   命令:docker logs -f 容器id
[aaa@qq.com ~]# docker logs -f 6383227303cd
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/xe.log" for further details.
Configuring Apex console
Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed
Starting web management console

PL/SQL procedure successfully completed.  
## 到这里看到上面的successfully 差不多就启动成功了

6、进入容器修改账号密码设置

# 查看运行的容器
[aaa@qq.com ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED               
6383227303cd        truevoly/oracle-12c   "/entrypoint.sh "        2 minutes ago     
# 进入容器,修改配置
[aaa@qq.com ~]# docker exec -it 6383227303cd /bin/bash
# 进入容器后,切换到oracle用户
aaa@qq.com:/# su oracle
# 进入sqlplus
aaa@qq.com:/$ $ORACLE_HOME/bin/sqlplus / as sysdba
# 设置密码有效期为无限制
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED
# 解锁system用户
SQL> alter user SYSTEM account unlock
# exit 退出
# ctrl + p + q 退出容器(注意,不要exit退出,防止容器直接关闭了)

######################################################################

OK,现在oracle数据库已经启动完毕,oracle连接的信息如下:

hostname: docker所在宿主机的ip
port: 1521
username: system
password: oracle
sid: xe

7、测试连接

Docker安装运行oracle数据库步骤

最近也是初学docker,特意拿来练练手,希望能够帮助大家~~~

只要学不死,就往死里学!