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

标签 python oracle docker dockerfile containers

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

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 下载了最新的客户端,我似乎也无法让它工作.

我的目录结构如下所示:
--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:
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文件:
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"]

关于python - 将 Oracle Instant 客户端安装到 Python cx_Oracle 的 Docker 容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58992954/

相关文章:

python - 使用 Python、Kubernetes api 调用 YAML 到 JSON

java - java.lang.NoSuchFieldError:ECS中启动时的SIGNING_REGION不会在本地发生

bash - eval $(docker-machine env默认值)在iterm启动脚本中不起作用

Python 线程 - 关键部分

python - 在测试和训练数据集中使用基于时间的拆分来拆分数据

python - 引发 TesseractError(proc.returncode, get_errors(error_string))

oracle - oracle 是否以特定的标准化形式存储 unicode 文本?

python - 如何使用 pip 安装 Python MySQLdb 模块?

java - 我可以强制 Java 忽略时区吗?

java - 使用瘦 jdbc 驱动程序创建 oracle 数据库触发器