- VSCode Version:
1.70.0
- Local OS Version:
Microsoft Windows [Version 10.0.19043.1826]
- Remote OS Version:
Ubuntu 20.04.4 LTS
- Remote Extension/Connection Type:
Containers
- Logs:
N/A
Steps to Reproduce:
-
clone the project & open with vscode
git clone https://github.com/doggy8088/devcontainer-dotnet-mssql-ipv6-issue.git
code devcontainer-dotnet-mssql-ipv6-issue
-
Reopen in Container
-
Here is the PORTS info.

-
Connect to localhost locally using sqlcmd
sqlcmd -S localhost -U sa -P P@ssw0rd -Q "SELECT 1;"
It will result:
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..
-
Connect to 127.0.0.1 locally using sqlcmd
sqlcmd -S 127.0.0.1 -U sa -P P@ssw0rd -Q "SELECT 1;"
It will run successfully.
-----------
1
(1 rows affected)
I really expected I can connect to the db container using localhost. It because the PORTS shows that.
During few hours research, I realized that Windows use IPv6 by default. When VSCode use IPv4 to do the port forwarding, connect to localhost will route to ::1 and it will failed.
Two suggestions:
-
Change the Local Address to show 127.0.01:1433 on the PORTS window.
-
Port forwarding support IPv6.
1.70.0Microsoft Windows [Version 10.0.19043.1826]Ubuntu 20.04.4 LTSContainersN/ASteps to Reproduce:
clone the project & open with vscode
Reopen in Container
Here is the
PORTSinfo.Connect to
localhostlocally usingsqlcmdsqlcmd -S localhost -U sa -P P@ssw0rd -Q "SELECT 1;"It will result:
Connect to
127.0.0.1locally usingsqlcmdsqlcmd -S 127.0.0.1 -U sa -P P@ssw0rd -Q "SELECT 1;"It will run successfully.
I really expected I can connect to the
dbcontainer usinglocalhost. It because thePORTSshows that.During few hours research, I realized that Windows use IPv6 by default. When VSCode use IPv4 to do the port forwarding, connect to
localhostwill route to::1and it will failed.Two suggestions:
Change the
Local Addressto show127.0.01:1433on thePORTSwindow.Port forwarding support
IPv6.