Connect docker python to SQL server with pyodbc

Need to Run:

sudo apt-get install gcc

need to add a odbcinst.ini file containing:

[FreeTDS]Description=FreeTDS Driver Driver=/usr/lib/x86_64-linux-gnu/odbc/ Setup=/usr/lib/x86_64-linux-gnu/odbc/

need to add folowing to docker file

ADD odbcinst.ini /etc/odbcinst.ini
RUN apt-get update
RUN apt-get install -y tdsodbc unixodbc-dev
RUN apt install unixodbc-bin -y
RUN apt-get clean -y

need to change connection in .py to

connection = pyodbc.connect('Driver={FreeTDS};'

Now the container compiles, and gets data from SQL server

Leave a Comment