项目中需要对接Oracle引入数据,然而产品连接提示Oracle异常,需要测试,故安装指定版本的Oracle客户端。
本文以Centos8为基础镜像构建Oracle11g oracle-instantclient的客户端镜像
准备条件
官方下载地址: https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
根据实际前往官网下载对应el8
版本的basic
、devel
、sqlplus
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