Have a container running python with pyodbc that connect to a Microsoft SQL Server (Microsoft SQL Server 2017 (RTM-CU14-GDR) (KB4494352) - 14.0.3103.1 (X64)).
It has been working fine on Docker Desktop 2.0.0.3 and Engine version 18.09.2. But after upgrade to Docker Desktop 2.1.0.0 and Engine 19.03.1 it has stopped working. I get a time out error from pyodbc, so it seems like a connection problem to the database. When I downgrade Docker everything works fine again. Does anybody know about any changes in Engine 19.03.1 that can be the reason for this?
Error from python:
Traceback (most recent call last):
File "test.py", line 17, in <module>
cnxn = pyodbc.connect(login_info)
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Dockerfile
FROM python:3.7.4-stretch
# --- Install pyodbc on Derbian Stretch 9
# https://github.com/mkleehammer/pyodbc/wiki/Install
RUN apt-get update \
# && apt-get install g++ \
&& apt-get install --yes unixodbc-dev \
&& pip install pyodbc==4.0.27
# --- Install Microsoft ODBC Driver
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
# Need some certificate fix to install msodbcsql17
RUN apt-get install --yes apt-transport-https ca-certificates \
&& apt-get update && ACCEPT_EULA=Y apt-get install --yes msodbcsql17
Python script:
import pyodbc
login_info = f"""\
DRIVER={{ODBC Driver 17 for SQL Server}};
SERVER=;
DATABASE=;
UID=;
PWD="""
cnxn = pyodbc.connect(login_info)
cursor = cnxn.cursor()
tsql = "SELECT @@version;"
with cursor.execute(tsql):
row = cursor.fetchone()
print(str(row[0]))
docker command:
docker build --tag=pyodbc .
docker run --rm -v %cd%:/usr/src/ -w /usr/src pyodbc python test.py