Django App inside Docker connecting to MS SQL Server via odbc/freeTds driver not working

We are deploying an app via a docker image into openshift. The app is using below. We’ve tried different ways to fixing the issue, with different drivers/versions of python, editing *.ini files inside the docker container, but without any success.

A simple connection test inside the docker generate the same error, as when we start the app inside openshift, see below. Any suggestions???

cnxn = pyodbc.connect(‘DRIVER={ODBC Driver 17 for SQL Server};SERVER=’+server+’;DATABASE=’+database+’;UID=’+username+’;PWD=’+ password)
Traceback (most recent call last):
File “”, line 1, in
pyodbc.Error: (‘IM004’, “[IM004] [unixODBC][Driver Manager]Driver’s SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)”)

app component
FROM python:3.7
MS SQL server, version 13.0.5026.0.

- -
‘dev’: {
‘ENGINE’: ‘sql_server.pyodbc’,
‘NAME’: ‘dbName’,
‘HOST’: ‘dbHost’,
‘USER’: ‘dbUser’,
‘PASSWORD’: ‘dbPass’,
‘driver’: ‘ODBC Driver 17 for SQL Server’,

- Docker -

  1. OS
    I have no name!@*************:/usr/src/app$ lsb_release -sirc

  2. relevant script inside docker

populate “ocbcinst.ini”

#RUN echo “[FreeTDS]\n
#Description = FreeTDS unixODBC Driver\n
#Driver = /usr/lib/x86_64-linux-gnu/odbc/\n
#Setup = /usr/lib/x86_64-linux-gnu/odbc/” >> /etc/odbcinst.ini

RUN echo “[ODBC Driver 17 for SQL Server]\n
Description=Microsoft ODBC Driver 17 for SQL Server\n
Trace=Yes” >> /etc/odbcinst.ini

RUN echo “[MSSQLServer]\n
Driver = ODBC Driver 17 for SQL Server\n
hostname = dbHost\n
Database = dbName” >> /etc/odbc.ini

This issue is fixed from our side.It turned out to be an user permission issue inside the docker, the app has to be started as root user, so odbc.ini etc files can be read correctly, odbc driver is set up correctly before but due to this it threw a very generic error that is quite misleading.