简体   繁体   中英

"DPI-1047: Cannot locate a 64-bit Oracle Client library: file too short" When running docker image to connect to oracle database

When trying to run my docker image, I am presented with the following error: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "oracle_lib/instantclient_21_4/libclntsh.so: file too short"

This is my dockerfile

FROM python:3.9

WORKDIR /app

RUN apt-get update -y
RUN apt-get install libaio1

COPY ../requirements.txt /app
RUN pip install -r requirements.txt

COPY ./ /app
ENV PYTHONPATH "${PYTHONPATH}:/app"
ENV PATH "${PATH}:/app"

EXPOSE 5000

CMD ["python", "products/product_db.py"]

product_db.py runs the following code to connect to the database: cx_Oracle.init_oracle_client(lib_dir="oracle_lib/instantclient_21_4", config_dir="oracle_config/Wallet_pricedb") which works completely fine when running linux on my computer and this error is not shown.

I have tried manually setting the required environment variables eg $TNS_ADMIN, $ORACLE_HOME, $LD_LIBRARY_PATH to the correct locations (which also worked when trying to connect to the oracle database through linux in vs code), but the same error is given when running the docker image. I also followed all the steps of the cx_Oracle 8 installation guide and still receive the same error.

  • Your error is a system error "oracle_lib/instantclient_21_4/libclntsh.so: file too short" that is wrapped in the DPI message. It looks like you have some file corruption or other OS error. How is Instant Client getting installed? Does SQL*Plus work?

  • With Instant Client don't set ORACLE_HOME

  • On Linux, the only effect of cx_Oracle.init_oracle_client(lib_dir="oracle_lib/instantclient_21_4") is to immediately load libraries. You still need to make sure that those libraries are in the system library search path (eg LD_LIBRARY_PATH, or via ldconfig ) before the process starts. But make sure you are passing the same directory as used in the system search path otherwise you might get odd behavior or errors.

  • cx_Oracle.init_oracle_client(config_dir="oracle_config/Wallet_pricedb") internally sets TNS_ADMIN so it will override any value of the variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM