2
votes

I am trying to dockerize a very simple python application with Oracle database connection and execute it on Docker. This application is executing fine on my local machine.

I was successfully able to build this application but getting an error while executing it on Docker.

DockerFile:

FROM python:3

ADD File.py /

RUN pip install cx_Oracle
RUN pip install pandas
RUN pip install openpyxl

CMD [ "python", "./File.py" ]

File.py:

import cx_Oracle
import pandas as pd

#creating database connection
dsn_tns = cx_Oracle.makedsn('dev-tr01.com', '1222', service_name='ast041.com')
conn = cx_Oracle.connect(user=r'usr', password='3451', dsn=dsn_tns)
c = conn.cursor()

query ='SELECT * FROM Employee WHERE ROWNUM <10'
result = pd.read_sql(query, con=conn)
result.to_excel("batchtable.xlsx")

conn.close()

Error:

docker run python_batchdriver:latest

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

1

1 Answers

0
votes

For cx_Oracle, you need to install Oracle Instant Client libraries too. See the cx_Oracle installation instructions.

There are various ways to automate installation in Docker. One example is:

RUN 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 instantclient* && \
    rm -f *jdbc* *occi* *mysql* *jar uidrvci genezi adrci && \
    echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && \
    ldconfig

You will also need the libaio or libaio1 package.

See Docker for Oracle Database Applications in Node.js and Python.

Also see Install Oracle Instant client into Docker container for Python cx_Oracle Note that the steps may be different if you are not using a Debian-based Linux distribution.