Python cx_Oracle용 도커 컨테이너에 Oracle Instant 클라이언트 설치
cx_Oracle 패키지를 사용하여 일부 python 스크립트가 포함된 도커 컨테이너를 통해 회사의 Oracle 데이터베이스에 연결하려고 합니다.컨테이너를 빌드하고 실행한 후 다음 오류가 발생합니다.
conn = cx_Oracle.connect("{0}/{1}@{2}".format(configOracle["username"], configOracle["password"],r"ed03:1521/configOracle["servername"]))
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
사용자 이름, 암호 및 서버 이름이 올바르게 입력되고 있는 Oracle 구성 파일이 있습니다.https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html 에서 최신 클라이언트를 다운로드해도 작동이 되지 않는 것 같습니다.
내 디렉토리 구조는 다음과 같습니다.
--TopDirectory
----instantclient
-------instantclient-basic-linux.x64-19.5.0.0.0dbru.zip
-------instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip
----hello_oracle.py
----Dockerfile
----requirements.txt
----configOracle.json
다음은 내 도커 파일입니다.
FROM python:3.7.5
#Oracle Client setup
ENV ORACLE_HOME /opt/oracle/instantclient_19_5
ENV LD_RUN_PATH=$ORACLE_HOME
COPY instantclient/* /tmp/
RUN \
mkdir -p /opt/oracle && \
unzip "/tmp/instantclient*.zip" -d /opt/oracle && \
ln -s $ORACLE_HOME/libclntsh.so.19.1 $ORACLE_HOME/libclntsh.so
# Working directory
WORKDIR /src
# Copying requirements.txt before entire build step
COPY requirements.txt /src/requirements.txt
RUN pip install --upgrade pip
# Installing necessary packages
RUN pip install -r requirements.txt
# Copying rest of files
COPY . /src
CMD ["python3", "/src/hello_oracle.py"]
여기 제 요구사항이 있습니다.txt 파일:
pandas
numpy
matplotlib
keras
cx_Oracle
sklearn
tensorflow
pyopenssl
ndg-httpsclient
pyasn1
많은 시간을 시도한 후에, 저는 마침내 이 도커 파일로 그것을 해결했습니다.
메모 패키지 관리를 위해 python 3.7, Django 3.0, Oracle Database 12c 및 Pipenv를 사용하고 있습니다.
FROM python:3.7.5-slim-buster
# Installing Oracle instant client
WORKDIR /opt/oracle
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 /opt/oracle/instantclient* \
&& rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci \
&& echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf \
&& ldconfig
WORKDIR /app
COPY . . # Copy my project folder content into /app container directory
RUN pip3 install pipenv
RUN pipenv install
EXPOSE 8000
# For this statement to work you need to add the next two lines into Pipfilefile
# [scripts]
# server = "python manage.py runserver 0.0.0.0:8000"
ENTRYPOINT ["pipenv", "run", "server"]
Oracle용 Python 드라이버의 최신 릴리스는 python-oracledb로 이름이 바뀌었으며 현재 기본적으로 '씬' 드라이버입니다.인스턴트 클라이언트는 필요하지 않습니다. 선택사항입니다.릴리스 발표를 참조하십시오.도커 파일은 다음과 같습니다.
FROM python:3.10-bullseye
RUN python -m pip install oracledb
옵션에서 python-oracledb의 'thick' 모드를 사용하려면 다음과 같은 Docker 파일을 사용할 수 있습니다.
FROM python:3.10-bullseye
WORKDIR /opt/oracle
RUN apt-get update && apt-get install -y libaio1
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 /opt/oracle/instantclient* && rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci && \
echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig
RUN python -m pip install oracledb
Oracle에는 https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers 에 Python cx_Oracle Docker 파일이 있고 https://github.com/orgs/oracle/packages 에 cx_Oracle 컨테이너가 있습니다.
Node.js 및 Python에는 Oracle Database Applications용 두 부분으로 구성된 블로그 포스트 시리즈 Docker가 있으며 다양한 설치 방법을 보여줍니다.또한 cx_Oracle 및 Docker에 대해 설명하는 Oracle 웹캐스트 녹화도 여기에 있습니다.
여전히 cx_Oracle 네임스페이스를 사용하는 경우 항상 Instant Client를 설치해야 하므로 솔루션에서 다음을 사용할 수 있습니다.
FROM python:3.10-bullseye
RUN apt-get update && apt-get install -y libaio1
WORKDIR /opt/oracle
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 /opt/oracle/instantclient* && rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci && \
echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig
RUN python -m pip install cx_Oracle
다른 기본 이미지를 사용하는 경우 wget 및 unzip을 명시적으로 설치해야 할 수 있습니다.
언급URL : https://stackoverflow.com/questions/58992954/install-oracle-instant-client-into-docker-container-for-python-cx-oracle
'itsource' 카테고리의 다른 글
커밋 순서 변경 (0) | 2023.06.26 |
---|---|
스프링 부트 속성 파일을 사용하여 Flyway 'baselineOnMigrate' 및 'baselineVersion' 설정 (0) | 2023.06.26 |
FastAPI + SQLAlchemy - datetime 필드가 있는 테이블에 항목을 게시할 때 잘못된 RequestError가 발생함 (0) | 2023.06.26 |
리포지토리 패턴을 올바르게 사용하는 방법 (0) | 2023.06.26 |
SQL "IN" 절에서 튜플 사용 (0) | 2023.06.21 |