【发布时间】:2019-11-10 11:11:52
【问题描述】:
我正在使用在 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
【问题讨论】:
-
对于未来的读者,请查看博客文章 Connecting to Oracle Cloud Autonomous Database through SQLAlchemy 和 cx_Oracle 文档 Connecting to Oracle Cloud Autononmous Databases。
标签: docker sqlalchemy oracle-cloud-infrastructure oracle18c