将 Oracle Instant 客户端安装到 Python cx_Oracle 的 Docker 容器中

Install Oracle Instant client into Docker container for Python cx_Oracle(将 Oracle Instant 客户端安装到 Python cx_Oracle 的 Docker 容器中)
本文介绍了将 Oracle Instant 客户端安装到 Python cx_Oracle 的 Docker 容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过我的 docker 容器连接到我公司的 Oracle 数据库,该容器包含我的一些带有包 cx_Oracle 的 python 脚本.构建并运行容器后,出现以下错误:

I'm trying to connect to an Oracle database at my company through my docker container that contains some of my python scripts with the package cx_Oracle. After i build and run the container, i get the following error:

conn = cx_Oracle.connect("{0}/{1}@{2}".format(configOracle["username"], configOracle["password"],r"ed03:1521/configOracle["servername"]))
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help

我有一个 Oracle 配置文件,其中用户名、密码和服务器名称来自并正确填写.即使从 https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html.

I have an Oracle config file where the username, password, and server name are coming from and being filled in correctly. I can't seem to get it to work even after downloading the latest client from https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html.

我的目录结构如下:

--TopDirectory
----instantclient
-------instantclient-basic-linux.x64-19.5.0.0.0dbru.zip
-------instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip
----hello_oracle.py
----Dockerfile
----requirements.txt
----configOracle.json

这是我的 Dockerfile:

Here is my Dockerfile:

FROM python:3.7.5

#Oracle Client setup
ENV ORACLE_HOME /opt/oracle/instantclient_19_5
ENV LD_RUN_PATH=$ORACLE_HOME

COPY instantclient/* /tmp/

RUN 
    mkdir -p /opt/oracle && 
    unzip "/tmp/instantclient*.zip" -d /opt/oracle && 
    ln -s $ORACLE_HOME/libclntsh.so.19.1 $ORACLE_HOME/libclntsh.so

# Working directory
WORKDIR /src
# Copying requirements.txt before entire build step
COPY requirements.txt /src/requirements.txt

RUN pip install --upgrade pip
# Installing necessary packages
RUN pip install -r requirements.txt
# Copying rest of files
COPY . /src
CMD ["python3", "/src/hello_oracle.py"]

这是我的 requirements.txt 文件:

Here is my requirements.txt file:

pandas
numpy
matplotlib
keras
cx_Oracle
sklearn
tensorflow
pyopenssl
ndg-httpsclient
pyasn1

推荐答案

试了好几个小时,终于用这个Dockerfile解决了

注意 我正在使用 python 3.7、Django 3.0、Oracle Database 12c 和 Pipenv 进行包管理

FROM python:3.7.5-slim-buster

# Installing Oracle instant client
WORKDIR    /opt/oracle
RUN        apt-get update && apt-get install -y libaio1 wget unzip 
            && wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip 
            && unzip instantclient-basiclite-linuxx64.zip 
            && rm -f instantclient-basiclite-linuxx64.zip 
            && cd /opt/oracle/instantclient* 
            && rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci 
            && echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf 
            && ldconfig

WORKDIR    /app
COPY       . .  # Copy my project folder content into /app container directory
RUN        pip3 install pipenv
RUN        pipenv install
EXPOSE     8000
# For this statement to work you need to add the next two lines into Pipfilefile
# [scripts]
# server = "python manage.py runserver 0.0.0.0:8000"
ENTRYPOINT ["pipenv", "run", "server"]

这篇关于将 Oracle Instant 客户端安装到 Python cx_Oracle 的 Docker 容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
Inserting NaN value into MySQL Database(将NaN值插入MySQL数据库)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)