Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ORA-12170: TNS:Connect timeout occurred while connecting to remote Oracle DB using cx_Oracle in Alpine-based Docker image

Sanket Parte4 days ago — edited 3 days ago

Hi all,

We are encountering the following error when attempting to connect to a remote Oracle 19c database using the cx_Oracle 8.3.0 Python client inside an Alpine-based Python Docker image:

cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred

Following is the python code which we are using:

import cx_Oracle
from django.conf import oracle_db_conn_str

# Connection string format: "<user>/<password>@<host>:<port>/<db>" 
conn = cx_Oracle.connect(oracle_db_conn_str)

Following is the part of our Dockerfile, which consist of oracle instant client installation:

FROM python:3.12.9-alpine3.21 AS base

# Install OS-level dependencies
ARG USER=user
ARG HTTP_PROXY
ARG HTTPS_PROXY

ENV ORACLE_BASE=/usr/lib/oracle/19.18/client64/lib

# Install dependencies
RUN addgroup $GROUP && adduser --disabled-password --gecos "" -S -s /bin/sh $USER -G $GROUP -D \
   && apk --no-cache --update add \
   openrc postgresql-client bash shadow curl logrotate \
   libaio libnsl libc6-compat \
   && apk add --virtual .build-deps gcc postgresql-dev python3-dev jpeg-dev zlib-dev \
   && curl -Lo /tmp/instantclient-basic.zip https://download.oracle.com/otn_software/linux/instantclient/1918000/instantclient-basic-linux.x64-19.18.0.0.0dbru.zip \
   && unzip /tmp/instantclient-basic.zip -d /tmp/ \
   && mkdir -p ${ORACLE_BASE} \
   && cp -r /tmp/instantclient_*/* ${ORACLE_BASE}/ \
   && rm -rf /tmp/instantclient-basic.zip /tmp/instantclient_* \
   && ln -s ${ORACLE_BASE}/libclntsh.so.19.1 /usr/lib/libclntsh.so \
   && ln -s ${ORACLE_BASE}/libocci.so.19.1 /usr/lib/libocci.so \
   && ln -s ${ORACLE_BASE}/libociicus.so /usr/lib/libociicus.so \
   && ln -s ${ORACLE_BASE}/libnnz19.so /usr/lib/libnnz19.so \
   && ln -s /usr/lib/libnsl.so.3.0.0 /usr/lib/libnsl.so.1 \
   && ln -s /lib64/ld-linux-x86-64.so.2 /usr/lib/ld-linux-x86-64.so.2 \
   && pip install $APP_DIR/misc/django-model-audit.zip
  
ENV LD_LIBRARY_PATH=${ORACLE_BASE}:${LD_LIBRARY_PATH}
ENV ORACLE_HOME=${ORACLE_BASE}
ENV TNS_ADMIN=${ORACLE_BASE}

Can anyone help us identify the cause of this issue? Are we missing any configurations? We would greatly appreciate any insights or suggestions on how to debug this further or potential solutions.

Comments

Processing

Post Details