简体   繁体   中英

How to locate Oracle Instant Client in Python in Docker CI/CD pipeline

I am trying to connect to oracle DB to execute some SQL queries and fetch data through a python script . I have imported cx_Oracle and tried connecting.I got the error as - Exception - DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help was raised.

I downloaded instaclient and used that in my script and it worked using the below commands :

         LOCATION = r"C:\instantclient_19_5"

         os.environ["PATH"] = LOCATION + ";" + os.environ["PATH"] 

But now I need to use this in CI CD pipeline. I have created a docker image for instaclient and python I am trying use this into my script. But I am not sure how to use add instaclient location in script (like the above code snippet) Could you please help me with this.

If you were deploying to Windows (or macOS), you could have used the new cx_Oracle 8 init_oracle_client() function, which is preferred to fiddling with PATH.

However it seems you are deploying to Linux, meaning the system library search path needs to contain all library directories before the process start. So you need to use ldconfig or set LD_LIBRARY_PATH as traditionally used on Linux. The cx_Oracle doc Installing cx_Oracle on Linux and Locating the Oracle Client Libraries covers this.

Also see sample docker images for Linux developers and for basic Oracle Instant Client . If you are not on an RPM based system, check out the sample Docker files in Docker for Oracle Database Applications in Node.js and Python .

In summary, download Oracle Instant Client Basic or Basic Light packages from here . If you got the ZIP files then run something like:

RUN echo /opt/oracle/instantclient_19_8 > /etc/ld.so.conf.d/oic.conf && \
    ldconfig

The details vary with what base Docker image you are using, and whether you want to install Instant Client from ZIP files or RPMs.

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