Docker SQL Server容器与Entity Framework Core连接失败求助
连接Docker容器中SQL Server失败问题
我使用以下命令创建SQL Server容器:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=********" -e "MSSQL_PID=Evaluation" -p 1433:1433 --name sqlserver --hostname sqlserver -d mcr.microsoft.com/mssql/server:2022-preview-ubuntu-22.04
我的连接字符串如下:
"Server=localhost,1433;Database=TemplateDb;User Id=sa;Password=********;Integrated Security=false;TrustServerCertificate=true"
连接时抛出异常:
Microsoft.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server: Could not open a connection to SQL Server)'
已确认的信息和尝试的操作:
- 使用Management Studio或Azure Data Studio可正常连接该容器,数据库已创建
- 已尝试重启容器、检查防火墙设置
- 通过
docker exec可连接容器,docker ps显示容器正在运行
内容的提问来源于stack exchange,提问作者Ondřej Halata
相关产品推荐
相关产品推荐

