Install Oracle Instant client into Docker container for Python cx_Oracle

后端 未结 2 1971
孤街浪徒
孤街浪徒 2020-12-16 04:08

I\'m trying to connect to an Oracle database at my company through my docker container that contains some of my python scripts with the package cx_Oracle. After i build and

相关标签:
2条回答
  • After many hours trying it, I finally solved it with this Dockerfile

    Note I am using python 3.7, Django 3.0, Oracle Database 12c and Pipenv for package management

    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"]
    
    0 讨论(0)
  • 2020-12-16 05:07

    One solution is to try:

    FROM python:3.7.4-slim-buster
    
    RUN apt-get update && apt-get install -y libaio1 wget unzip
    
    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
    

    If you use a different base image you may not need to explicitly install unzip or libaio1. If you're happy using ADD, then you won't need wget either.

    Also there is a recent Oracle webcast recording discussing cx_Oracle and Docker here.

    Update: A new blog post series on this is at Docker for Oracle Database Applications in Node.js and Python.

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

    0 讨论(0)
提交回复
热议问题