python and oracle client on docker image
Asked Answered
S

1

7

I want to create a docker image with oracle client and cx_oracle of python. I am using multi stage docker to build the image but I am missing an env variable due to which cx_oracle is not able to find an oracle client library.

FROM oraclelinux:7-slim
RUN  curl -o /etc/yum.repos.d/public-yum-ol7.repo https://yum.oracle.com/public-yum-ol7.repo && \
     yum-config-manager --enable ol7_oracle_instantclient && \
     yum -y install oracle-instantclient18.3-basic oracle-instantclient18.3-devel oracle-instantclient18.3-sqlplus && \
     rm -rf /var/cache/yum && \
     echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient18.3.conf && \
     ldconfig
ENV PATH=$PATH:/usr/lib/oracle/18.3/client64/bin    

FROM python:slim
COPY ./requirement.txt ./requirement.txt
RUN pip install -r ./requirement.txt
COPY --from=0 /usr/lib/oracle/18.3/client64/lib /root/usr/lib/oracle/18.3/client64/lib
COPY --from=0 /usr/lib/oracle/18.3/client64/bin /root/usr/lib/oracle/18.3/client64/bin
ENV PATH=$PATH:/root/usr/lib/oracle/18.3/client64/bin:/root/usr/lib/oracle/18.3/client64/lib
ENV ORACLE_HOME=/root/usr/lib/oracle/18.3/client64/:$ORACLE_HOME
ENV LD_LIBRARY_PATH=/root/usr/lib/oracle/18.3/client64/:$LD_LIBRARY_PATH
RUN echo $PATH
RUN echo $ORACLE_HOME
RUN chmod 755 /root/usr/lib/oracle/18.3/client64/lib/*
RUN ls -l /root/usr/lib/oracle/18.3/client64/lib
CMD ["chmod","755","/root/usr/lib/oracle/18.3/client64/lib/*"]
CMD ["ls", "-l" ,"/root/usr/lib/oracle/18.3/client64/lib"]
CMD ["python","test.py"]

Below is the error

DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux
Spaniel answered 6/12, 2018 at 12:30 Comment(2)
You have a mismatch between what you put in /etc/ld.so.conf.d and what you set your environment variables to! You don't need to do both, though. And you definitely don't need to (or want to!) set the environment variable ORACLE_HOME.Paternity
Oracle has various Python and cx_Oracle RPMs that you may be able to make use of: yum.oracle.com/oracle-linux-python.htmlNavarrette
N
3

Oracle has Python Dockerfiles at https://github.com/oracle/docker-images/tree/main/OracleLinuxDevelopers

Also see https://blogs.oracle.com/opal/docker-for-oracle-database-applications-in-nodejs-and-python-part-1

Navarrette answered 26/8, 2020 at 23:16 Comment(4)
Do you know if Oracle has any Windows Docker images? I can't see any at github.com/oracle/docker-images I'm looking for an Oracle client with SQL*PlusMonarchy
I'm not aware of any. If you just want to run SQL*Plus, use a Linux container. If you want something more GUI, then use SQLcl or SQLDeveloper in your own container.Navarrette
Thanks, yeah I'm going to add it manually to my own container. Very poor Windows support from Oracle.Monarchy
For Windows, see github.com/oracle/docker-images/issues/… for a link to some steps. (Also, as noted in that link, even SQL Server support for Windows Containers was suspended in 2021)Navarrette

© 2022 - 2024 — McMap. All rights reserved.