cx_Oracle on Docker : DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so

I’m trying to build a Docker image with cx_Oracle.

Here is the Dockerfile I’m using :

FROM oraclelinux:7-slim

ARG release=18
ARG update=3

RUN  yum -y install oracle-release-el7 && 
     yum-config-manager --enable ol7_oracle_instantclient && 
     yum -y install oracle-instantclient${release}.${update}-basic && 
     rm -rf /var/cache/yum

COPY ./fetch_session_iptv.py /opt/
COPY ./conf/fetch_session_iptv.conf /opt/conf/
#COPY ./conf/certs/* /opt/conf/certs/
COPY ./logs /opt/logs

RUN yum install -y 
    #https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/oracle-instantclient18.3-basic-18.3.0.0.0-2.x86_64.rpm 
    https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/python36-cx_Oracle-7.0-1.0.2.el7.x86_64.rpm 
    https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/python36-pytz-2016.10-2.0.1.el7.noarch.rpm

COPY ./python_requirements/elasticsearch-7.8.0-py2.py3-none-any.whl .
COPY ./python_requirements/certifi-2020.4.5.2-py2.py3-none-any.whl .
COPY ./python_requirements/urllib3-1.25.9-py2.py3-none-any.whl .

RUN pip3 install --user 
    certifi-2020.4.5.2-py2.py3-none-any.whl 
    urllib3-1.25.9-py2.py3-none-any.whl 
    elasticsearch-7.8.0-py2.py3-none-any.whl


#CMD ["/bin/bash"]

CMD [ "python3", "/opt/fetch_session_iptv.py" ]

This is directly from Oracle documentation : ODPI-C Installation

The image seems to build correctly :

Sending build context to Docker daemon  3.214GB
Step 1/13 : FROM oraclelinux:7-slim
 ---> 7442ca158991
Step 2/13 : ARG release=18
 ---> Using cache
 ---> a9601d8b5721
Step 3/13 : ARG update=3
 ---> Using cache
 ---> 9c82b94480af
Step 4/13 : RUN  yum -y install oracle-release-el7 &&      yum-config-manager --enable ol7_oracle_instantclient &&      yum -y install oracle-instantclient${release}.${update}-basic &&      rm -rf /var/cache/yum
 ---> Using cache
 ---> aadfe1be7fe3
Step 5/13 : COPY ./fetch_session_iptv.py /opt/
 ---> Using cache
 ---> b3346172a4d4
Step 6/13 : COPY ./conf/fetch_session_iptv.conf /opt/conf/
 ---> Using cache
 ---> a0b0def735fc
Step 7/13 : COPY ./logs /opt/logs
 ---> Using cache
 ---> 32e1a82972f7
Step 8/13 : RUN yum install -y  https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/python36-cx_Oracle-7.0-1.0.2.el7.x86_64.rpm     https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/python36-pytz-2016.10-2.0.1.el7.noarch.rpm
 ---> Running in 50a6545982aa
Loaded plugins: ovl
Examining /var/tmp/yum-root-5QFxy8/python36-cx_Oracle-7.0-1.0.2.el7.x86_64.rpm: python36-cx_Oracle-7.0-1.0.2.el7.x86_64
Marking /var/tmp/yum-root-5QFxy8/python36-cx_Oracle-7.0-1.0.2.el7.x86_64.rpm to be installed
Examining /var/tmp/yum-root-5QFxy8/python36-pytz-2016.10-2.0.1.el7.noarch.rpm: python36-pytz-2016.10-2.0.1.el7.noarch
Marking /var/tmp/yum-root-5QFxy8/python36-pytz-2016.10-2.0.1.el7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package python36-cx_Oracle.x86_64 0:7.0-1.0.2.el7 will be installed
--> Processing Dependency: python(abi) = 3.6 for package: python36-cx_Oracle-7.0-1.0.2.el7.x86_64
--> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python36-cx_Oracle-7.0-1.0.2.el7.x86_64
---> Package python36-pytz.noarch 0:2016.10-2.0.1.el7 will be installed
--> Running transaction check
---> Package python3.x86_64 0:3.6.8-13.0.1.el7 will be installed
--> Processing Dependency: python3-pip for package: python3-3.6.8-13.0.1.el7.x86_64
--> Processing Dependency: python3-setuptools for package: python3-3.6.8-13.0.1.el7.x86_64
---> Package python3-libs.x86_64 0:3.6.8-13.0.1.el7 will be installed
--> Processing Dependency: libtirpc.so.1()(64bit) for package: python3-libs-3.6.8-13.0.1.el7.x86_64
--> Running transaction check
---> Package libtirpc.x86_64 0:0.2.4-0.16.el7 will be installed
---> Package python3-pip.noarch 0:9.0.3-7.el7_8 will be installed
---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch   Version           Repository                    Size
================================================================================
Installing:
 python36-cx_Oracle x86_64 7.0-1.0.2.el7     /python36-cx_Oracle-7.0-1.0.2.el7.x86_64
                                                                          1.3 M
 python36-pytz      noarch 2016.10-2.0.1.el7 /python36-pytz-2016.10-2.0.1.el7.noarch
                                                                          919 k
Installing for dependencies:
 libtirpc           x86_64 0.2.4-0.16.el7    ol7_latest                    89 k
 python3            x86_64 3.6.8-13.0.1.el7  ol7_latest                    69 k
 python3-libs       x86_64 3.6.8-13.0.1.el7  ol7_latest                   7.0 M
 python3-pip        noarch 9.0.3-7.el7_8     ol7_latest                   1.8 M
 python3-setuptools noarch 39.2.0-10.el7     ol7_latest                   628 k

Transaction Summary
================================================================================
Install  2 Packages (+5 Dependent packages)

Total size: 12 M
Total download size: 9.5 M
Installed size: 50 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                              1.5 MB/s | 9.5 MB  00:06     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libtirpc-0.2.4-0.16.el7.x86_64                               1/7 
  Installing : python3-libs-3.6.8-13.0.1.el7.x86_64                         2/7 
  Installing : python3-setuptools-39.2.0-10.el7.noarch                      3/7 
  Installing : python3-pip-9.0.3-7.el7_8.noarch                             4/7 
  Installing : python3-3.6.8-13.0.1.el7.x86_64                              5/7 
  Installing : python36-cx_Oracle-7.0-1.0.2.el7.x86_64                      6/7 
  Installing : python36-pytz-2016.10-2.0.1.el7.noarch                       7/7 
  Verifying  : python3-3.6.8-13.0.1.el7.x86_64                              1/7 
  Verifying  : libtirpc-0.2.4-0.16.el7.x86_64                               2/7 
  Verifying  : python36-cx_Oracle-7.0-1.0.2.el7.x86_64                      3/7 
  Verifying  : python3-libs-3.6.8-13.0.1.el7.x86_64                         4/7 
  Verifying  : python3-setuptools-39.2.0-10.el7.noarch                      5/7 
  Verifying  : python36-pytz-2016.10-2.0.1.el7.noarch                       6/7 
  Verifying  : python3-pip-9.0.3-7.el7_8.noarch                             7/7 

Installed:
  python36-cx_Oracle.x86_64 0:7.0-1.0.2.el7                                     
  python36-pytz.noarch 0:2016.10-2.0.1.el7                                      

Dependency Installed:
  libtirpc.x86_64 0:0.2.4-0.16.el7           python3.x86_64 0:3.6.8-13.0.1.el7  
  python3-libs.x86_64 0:3.6.8-13.0.1.el7     python3-pip.noarch 0:9.0.3-7.el7_8 
  python3-setuptools.noarch 0:39.2.0-10.el7 

Complete!
Removing intermediate container 50a6545982aa
 ---> 3345ba39b755
Step 9/13 : COPY ./python_requirements/elasticsearch-7.8.0-py2.py3-none-any.whl .
 ---> dcc4f0c5a5c5
Step 10/13 : COPY ./python_requirements/certifi-2020.4.5.2-py2.py3-none-any.whl .
 ---> e47c23f75225
Step 11/13 : COPY ./python_requirements/urllib3-1.25.9-py2.py3-none-any.whl .
 ---> f850ea09150d
Step 12/13 : RUN pip3 install --user    certifi-2020.4.5.2-py2.py3-none-any.whl urllib3-1.25.9-py2.py3-none-any.whl     elasticsearch-7.8.0-py2.py3-none-any.whl
 ---> Running in d01bf60be689
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Processing /certifi-2020.4.5.2-py2.py3-none-any.whl
Processing /urllib3-1.25.9-py2.py3-none-any.whl
Processing /elasticsearch-7.8.0-py2.py3-none-any.whl
Installing collected packages: certifi, urllib3, elasticsearch
Successfully installed certifi-2020.4.5.2 elasticsearch-7.8.0 urllib3-1.25.9
Removing intermediate container d01bf60be689
 ---> 4d38468f3a00
Step 13/13 : CMD [ "python3", "/opt/fetch_session_iptv.py" ]
 ---> Running in c2fdb466cd69
Removing intermediate container c2fdb466cd69
 ---> a614ef5071ac
Successfully built a614ef5071ac
Successfully tagged kansas-fetch:1.5-SNAPSHOT

But when I try to run it I get the following error message, even though Oracle Client is supposed to be installed :

Traceback (most recent call last):
python_metro_kansas_sql |   File "/opt/fetch_session_iptv.py", line 27, in <module>
python_metro_kansas_sql |     with cx_Oracle.connect("test","test", "test") as connection:
python_metro_kansas_sql | cx_Oracle.DatabaseError: 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 for help

Any idea how to fix this?

I tried with different versions for Oracle Client and cx_Oracle, but it makes no difference.

Source: StackOverflow