项目中需要对接Oracle引入数据,然而产品连接提示Oracle异常,需要测试,故安装指定版本的Oracle客户端。

本文以Centos8为基础镜像构建Oracle11g oracle-instantclient的客户端镜像

准备条件

官方下载地址: https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

根据实际前往官网下载对应el8版本的basicdevelsqlplus RPM包。

镜像制作

填写Dockerfile
其中ORACLE_BASE的地址需要填写实际的/usr/lib/oracle/地址,其他参数也需要同步修改。

以下为Dockerfile文件内容,根据实际情况进行改动。

FROM centos:8
WORKDIR /root/
RUN rm -rf /etc/yum.repos.d/* && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo && sed -i -e"s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-* && sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-* && yum clean all && yum makecache
RUN dnf install libaio libnsl -y
ADD oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm /root/
ADD oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm /root/
ADD oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm /root/

RUN rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm && rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm && rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

ENV ORACLE_BASE=/usr/lib/oracle/11.2
ENV ORACLE_VERSION=11.2
ENV ORACLE_HOME=/usr/lib/oracle/11.2/client64
ENV LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
ENV SQLPATH=$ORACLE_HOME/lib/network/admin
ENV TNS_ADMIN=$ORACLE_HOME/lib/network/admin
ENV NLS_LANG=AMERICAN_AMERICA.AL32UTF8
ENV PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
构建镜像
docker build -t oracle_client:11.2 .

测试镜像

运行镜像
docker run --rm -it oracle_client:11.2 bash
连接测试
  • username/password:数据库用户名和密码
  • host:数据库服务器IP或主机名
  • port(可选):监听端口,默认1521
  • service_name(可选):数据库服务名或SID
sqlplus username/password@host[:port][/service_name]

示例:

[root@0cf72be63bfc ~]# sqlplus Lolicp/Lolicp_123@10.10.10.11:1521/lolicp_orcl

SQL*Plus: Release 11.2.0.4.0 Production on Mon May 26 08:20:58 2025

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


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

SQL> SELECT * FROM v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0    Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

参考文档:https://www.cnblogs.com/dcwange/p/15188218.html

END

本文标题:使用Docker构建oracle-instantclient 11.2客户端镜像

本文作者:宇宙最帅的男人

本文链接:https://lolicp.com/docker/202526752.html

版权声明:转载或者引用本文内容请注明来源及原作者,本文著作权归 (lolicp.com) 所有。

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

最后修改:2025 年 05 月 26 日
如果觉得我的文章对你有用,请随意赞赏