mssql-docker
mssql-docker copied to clipboard
Impossible to connect to MSSQL Server 2019 on docker container
Please first make sure you have looked at:
- Documentation: https://github.com/mkleehammer/pyodbc/wiki - I read a lot of infor about pyodbc, unixODBC, odbcinst
- Other issues
Environment
To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:
-
Python: 3.11.2 64-bit
-
pyodbc: 4.0.35
-
OS: Python on Windows 10 Pro x64
-
DB: MSSQL Server 2019 on docker container - image: mssql/server:2019-latest
-
driver: ODBC Driver 17 for SQL Server
-
On Container: unixODBC 2.3.11
Issue
I have the docker container in Synology NAS (AMD 64), IP, example: 192.169.0.3 port for container 2443
- When I try to connect with driver:
import pyodbc conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.169.0.3,2443;UID=SA;PWD=mypassword')
Error:
Traceback (most recent call last):
File "c:\Users\vm\Desktop\SQL Server\sql-connection.py", line 10, in
- When I try to connect with DSN (DSN is configured in container, MSSQLServerDatabase is the name of DSN):
import pyodbc conn = pyodbc.connect('DSN=MSSQLServerDatabase;UID=SA;PWD=mypassword')
Error:
Traceback (most recent call last):
File "c:\Users\vm\Desktop\SQL Server\sql-connection.py", line 9, in
How you can see, the odbc cannot connect, but when I connect to database with VSCode or SQL Server Management Studio I connect without problems.
Please, can you help me?
Thanks in advance!
Hi there.
Did you run the container using --network=host?
Your IP of the server seems to be in your local network. The container can not see your local network, unless you run it with the command above.
Cheers
@retooooo
I too have a similar issue so I thought I would try your suggestion, so in my Power Shell 7.3 terminal
docker run -e 'ACCEPT_EULA=Y' -e '<Password>' `
-p 1433:1433 --name sql2 --hostname sql2 --network=host`
-d `
mcr.microsoft.com/mssql/server:2019-latest
9febe27bd08ef325f1f56ef9b47ef66ce2b5ba1afc7ce62ca91fd74235b45110
docker: Error response from daemon: network host
not found.
By contrast I have SQL1 running without the network setting, I just can't connect to it 😒
@retooooo Do you have the firewall turned on for your NAS? I too have a Synology NAS with sql server running in a docker container and have no issues. I also run it locally for development with no issues.