Skip to content
Mathieu Rampant edited this page May 23, 2023 · 1 revision

Prerequisites

Both the Oracle Instant Client and the python-oracledb libraries need to be installed in the container, which means a new image of NEMO needs to be build.

If using docker-compose, this can be done by creating a file named Dockerfile_nemo_oracle in the same folder as your docker-compose.yml with the following content:

# Update NEMO's version accordingly 
FROM nanofab/nemo:4.5.5 

ENV ORACLE_CLIENT_VERSION=21.10.0.0.0
ENV ORACLE_CLIENT_VERSION_UNPACKED=21_10
ENV ORACLE_DB_PYTHON_VERSION=1.3.1
ENV ORACLE_CLIENT_INSTALL_FOLDER=/opt/oracle

# Install Oracle Basic Client and update runtime link path
RUN apt-get install -y libaio1
RUN mkdir --parents ${ORACLE_CLIENT_INSTALL_FOLDER}
WORKDIR ${ORACLE_CLIENT_INSTALL_FOLDER}
RUN wget https://download.oracle.com/otn_software/linux/instantclient/$(echo "$ORACLE_CLIENT_VERSION" | sed -e 's/\.//g')/instantclient-basic-linux.x64-${ORACLE_CLIENT_VERSION}dbru.zip
RUN unzip instantclient-basic-linux.x64-${ORACLE_CLIENT_VERSION}dbru.zip
RUN echo ${ORACLE_CLIENT_INSTALL_FOLDER}/instantclient_${ORACLE_CLIENT_VERSION_UNPACKED}/ > /etc/ld.so.conf.d/oracle-instantclient.conf
RUN ldconfig

RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install oracledb==${ORACLE_DB_PYTHON_VERSION}

# Test Oracle client installation
RUN python3 -c 'import oracledb; oracledb.init_oracle_client()'

Then add the following in the nemo service of your docker-compose.yml

container_name: "nemo"
image: nemo_oracle:4.5.5
build:
  context: .
  dockerfile: Dockerfile_nemo_oracle

Important note: when updating to a new version of NEMO, the FROM section of the Dockerfile_nemo_oracle file will need to be updated accordingly

Settings

To use Oracle with NEMO you'll also need to update the settings.py file as follows:

At the very top of the file, add:

# Oracle setup
import sys
import oracledb
oracledb.version = "8.3.0"
sys.modules["cx_Oracle"] = oracledb
oracledb.init_oracle_client()

Then change the ENGINE property of the DATABASES variable to the following:

DATABASES = {
  ..
  "ENGINE": "django.db.backends.oracle",
  ..
}