So apparently your Dockerfile already has the required commands to install pyodbc. Therefore your container should already have
- gcc-c++
- python3-devel
- unixODBC-devel
Now instead of installing freetds from EPEL (or wherever) your Dockerfile will need to perform the following (which uses the latest stable version of FreeTDS at the time of writing):
curl https://www.freetds.org/files/stable/freetds-1.2.18.tar.gz > freetds-1.2.18.tar.gz
tar -xvzf freetds-1.2.18.tar.gz
cd freetds-1.2.18/
./configure
make
sudo make install
echo "" | sudo tee -a /etc/odbcinst.ini > /dev/null
echo "[FreeTDS_1.2.18]" | sudo tee -a /etc/odbcinst.ini > /dev/null
echo "Driver=/usr/local/lib/libtdsodbc.so" | sudo tee -a /etc/odbcinst.ini > /dev/null
Then you should be able to create a pyodbc connection like so:
>>> import pyodbc
>>> cnxn = pyodbc.connect("DRIVER=FreeTDS_1.2.18;SERVER=192.168.0.179;PORT=49242;UID=sa;PWD=_whatever_;")
>>> print(cnxn.execute("SELECT @@VERSION").fetchval())
Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) - 14.0.2037.2 (X64)
Nov 2 2020 19:19:59
Copyright (C) 2017 Microsoft Corporation
Express Edition (64-bit) on Windows 8.1 Pro 6.3 <X64> (Build 9600: )
>>> print(cnxn.getinfo(pyodbc.SQL_DRIVER_NAME))
libtdsodbc.so
>>> print(cnxn.getinfo(pyodbc.SQL_DRIVER_VER))
01.02.0018
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…