Install Oracle Instant client into Docker container for Python cx_Oracle Install Oracle Instant client into Docker container for Python cx_Oracle oracle oracle

Install Oracle Instant client into Docker container for Python cx_Oracle


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 clientWORKDIR    /opt/oracleRUN        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 \            && ldconfigWORKDIR    /appCOPY       . .  # Copy my project folder content into /app container directoryRUN        pip3 install pipenvRUN        pipenv installEXPOSE     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 has Python Dockerfiles at https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers

Update: Oracle has containers at https://github.com/orgs/oracle/packages

There is a two-part blog post series Docker for Oracle Database Applications in Node.js and Python that shows various ways to install. Also there is an Oracle webcast recording discussing cx_Oracle and Docker here.

For example, one solution is to use:

FROM python:3.7.4-slim-busterRUN apt-get update && apt-get install -y libaio1 wget unzipWORKDIR /opt/oracleRUN 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 && ldconfigRUN 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.