Trouble connecting to SQL Server with sqlcmd from inside Docker Trouble connecting to SQL Server with sqlcmd from inside Docker docker docker

Trouble connecting to SQL Server with sqlcmd from inside Docker


Judging by the nmap output you have shared I believe this to be a firewall issue or the server SQL Server itself blocks access. According to man nmap:

The state is either open, filtered, closed, or unfiltered [... ] Filtered. means that a firewall, filter, or other network obstacle is blocking the port so that Nmap cannot tell whether it is open or closed.

Reading the sqlcmd output (A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible) also points in this direction according to this Microsoft post which also offers some possible solutions.

IF the SQL Server is managed by yourself, you may check its logs to see why it refuses your connection and also add a firewall rule to allow access from your container. IF that's not the case, you may need to talk with the admin of that server and ask him to add your IP in the firewall list/accepted connections list in the server's configuration file.

If firewall is not your issue, please try applying the below settings to your SQL Server and re-test the connection.

Set "Listen to All" to No in the SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for [instance name]. And under IP Address change 127.0.0.1 to the [ip] used to connect. Don't forget to restart the SQL Server!

Other tip: check your firewall (or temporaly disable it for testing). Also allow remote connections in SQL Server properties > Connections. See above posts.

Life safer was this command: nc -zv <ip> 1433
It should say Connection to 1433 port [tcp/ms-sql-s] succeeded!

The original source is here.


Reading from your question, I'm assuming you want to connect to your local SQL Server from inside Docker.

SQL Server can be connected to over TCP/IP:

  1. Open SQL Server Configuration Manager and make sure TCP/IP is enabled;

  2. Make sure SQL Server is listening on all IP addresses.