'How to connect to Docker container with localhost instead of 127.0.0.1
I am running a mcr.microsoft.com/mssql/server docker container for local development that works perfectly on one machine.
But on my laptop the container is sometimes inaccessible.
If I try to connect through SQL Server Management Studio I can connect through localhost, [::1], 127.0.0.1 or ".". This works perfectly.
But if I run sqlcmd, dotnet or Azure Data Studio, only 127.0.0.1 and [::1] connections will work.
When I try to connect to localhost or ".", I get the message:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. .
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
I could change my behavior to only work with 127.0.0.1, but this requires me to change a bunch of project files where I am working on with a larger team.
I have searched online and found that localhost sometimes does not work for WSL 2. But I have successfully tested my WSL 2 setup and as said before I am able to connect with SQL Server Management Studio.
I have also tried disabling my Firewall.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
