'docker-compose: Cannot locate a 64-bit Oracle Client library error

I'm trying to make use of cx_Oracle in a python container (making use of the instantclient). If I build this container normally, everything works and the instaclient library is found. However if I build this using docker-compose, the library is not found. This must be a path problem.

I have added code that will search for the instantclient library. When building normally, this search returns the correct path. When using the docker-compose build, "Nothing" is returned.

I have used bash on both containers to check for the instantclient folder, and for both the instantclient folder is visible.

Is there anything special about the paths when using docker-compose?

Dockerfile:

# pull official base image
FROM python:3.9.5-slim-buster

# set work directory
WORKDIR /usr/src/app

## Note if you set lib_dir on Linux and related platforms, you must still have configured the system library search path to include that directory before starting Python.
RUN apt-get update && apt-get install -y libaio1 wget unzip \
  && 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 /usr/src/app/instantclient* \
  && rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci \
  && echo /usr/src/app/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf \
  && ldconfig

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

# copy project
COPY . /usr/src/app/

CMD ["python3", "./project/__init__.py"]

docker-compose.yml:

version: '3'

services:
  web:
    build: ./services/web
    command: python manage.py run -h 0.0.0.0
    ports:
      - 5001:5000
    env_file:
      - ./.env.dev

Python script:

import cx_Oracle
import os

app = Flask(__name__)

# Test to see if the cx_Oracle is recognized
print(cx_Oracle.version)   # this returns 8.0.1 for me

def find(name, path):
    for root, dirs, files in os.walk(path):
        if name in files:
            return os.path.join(root, name)

instaclient_path = find('instantclient','/')
print('instaclient path')
print(instaclient_path)


cx_Oracle.init_oracle_client(lib_dir=instaclient_path)

# This fails for me at this point 
cx_Oracle.clientversion() 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source