0

我正在使用在 docker 容器中部署 python-flask 应用程序的 oracle 云机器。
我正在尝试启动从应用程序到 Oracle 自治数据库的连接。
此连接由 python ORM SQLAlchemy 建立

与mysql的连接建立没有任何问题,详细信息如下。

engine = create_engine(
                'mysql+mysqlconnector://username:password@host:3306/databasename')
            cls.session_factory = sessionmaker(bind=engine)
            cls.base = declarative_base(bind=engine)

但是当我尝试使用 cx_oracle 驱动程序连接到 oracle 数据库时,它会抛出一个错误。

engine = create_engine(
                'oracle+cx_oracle://username:password@host:1522/databasename')
            cls.session_factory = sessionmaker(bind=engine)
            cls.base = declarative_base(bind=engine)

抛出的错误是:

sqlalchemy.exc.DatabaseError: (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 客户端库,然后下载并安装。

RUN apt-get update && apt-get install unzip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basiclite-linux.x64-19.3.0.0.0dbru.zip
RUN unzip instantclient-basiclite-linux.x64-19.3.0.0.0dbru.zip
RUN apt-get update && apt-get install libaio1
RUN ldconfig

但问题依然存在。

有没有人尝试从 python 应用程序创建到 Oracle 自治数据库的连接,即使它不是来自 docker 容器,甚至没有 sql-alchemy

更新

仍然面临这个问题。我正在粘贴下面的确切 dockerfile 以供参考。


FROM python:3.6-buster
RUN echo 'setting workdir'
WORKDIR /app

RUN echo 'running docker, install dependencies of docker file '
ADD requirements.txt /app/requirements.txt
RUN echo 'now installing from req.txt if any left'
RUN pip install -r /app/requirements.txt
RUN echo 'copying everything to app'
COPY . /app

RUN mkdir opt && cd opt && \
    wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basiclite-linux.x64-19.3.0.0.0dbru.zip && \
    unzip instantclient-basiclite-linux.x64-19.3.0.0.0dbru.zip && \
    echo /instantclient_19_3 > /etc/ld.so.conf.d/oracle-instantclient.conf && \
    cd instantclient_19_3 && ls -lrt && ldconfig

ENV TNS_ADMIN=/app/keys
RUN ls -lrt
RUN echo 'port exposed'
EXPOSE 5060
CMD ["gunicorn", "-b", "0.0.0.0:5060", "-t","120", "wsgi"]

错误信息:

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


4

2 回答 2

3

您错过了 Instant Client安装说明的一个步骤。在运行之前,ldconfig您需要更新库搜索路径配置,以便找到 Instant Client 库。

将第一个路径更改为要将文件解压缩到的目录:

echo /opt/oracle/instantclient_19_3 > /etc/ld.so.conf.d/oracle-instantclient.conf
于 2019-11-11T05:33:07.390 回答
0

感谢@Jones 的精彩 ppt,在它的帮助下,我能够解决我的问题。我正在发布完整的 dockerfile,以防其他人也被卡住。

FROM python:3.7.4-slim-buster

RUN apt-get update && apt-get install -y libaio1 wget
RUN apt-get install -y unzip
WORKDIR /opt/oracle
RUN wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip
RUN unzip instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
    rm -f instantclient-basic-linux.x64-19.3.0.0.0dbru.zip
RUN cd /opt/oracle/instantclient_19_3 && rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci
RUN echo /opt/oracle/instantclient_19_3 > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig

RUN echo 'running docker, install dependencies of docker file '
ADD requirements.txt /app/requirements.txt
RUN echo 'now installing from req.txt if any left'
RUN pip install -r /app/requirements.txt
RUN echo 'copying everything to app'
COPY . /opt/oracle

COPY /keys  /opt/oracle/instantclient_19_3/network/admin

RUN echo 'port exposed'
EXPOSE 5060
CMD ["gunicorn", "-b", "0.0.0.0:5060", "-t","120", "wsgi"]

我已经在应用程序中移动了包含 oracle ADB 钱包详细信息的密钥文件夹。requirements.txt 文件包含我的依赖项。

于 2019-11-17T12:07:15.917 回答