如何从 Linux Docker 容器连接到本地 SQL Server [英] How to Connect to Local SQL Server From Linux Docker Container

查看:42
本文介绍了如何从 Linux Docker 容器连接到本地 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在我的 Windows 机器上运行的 linux Docker 容器连接到我的本地 SQL Server 实例.在 Windows 下运行时,我可以使用 Data Source=localhost 成功连接.我发现 localhost 在linux 上的连接字符串,所以这里是我也尝试过但失败的:

I am trying to connect to my local instance of SQL Server using a linux Docker container running on my Windows machine. I can connect successfully using Data Source=localhost when running under Windows. I've discovered that localhost is not supported in a connection string on linux, so here is what I've also tried and failed with:

  • Data Source=localhost
  • 数据源=localhost,1433
  • 数据源=127.0.0.1
  • 数据源=127.0.0.1,1433
  • 数据源=127.0.0.11
  • 数据源=127.0.0.11,1433
  • Data Source=172.23.0.1 - 我的本地 IP 地址
  • 数据源=172.23.0.1,1433
  • Data Source=localhost
  • Data Source=localhost,1433
  • Data Source=127.0.0.1
  • Data Source=127.0.0.1,1433
  • Data Source=127.0.0.11
  • Data Source=127.0.0.11,1433
  • Data Source=172.23.0.1 - My local IP Address
  • Data Source=172.23.0.1,1433

我的本​​地 SQL Server 实例不允许远程连接.我怀疑这就是我无法连接的原因.我是否需要允许远程连接才能使其正常工作?我可以在不这样做的情况下完成这项工作吗?

My local SQL Server instance does not allow remote connections. I suspect this is why I cannot connect. Do I need to allow remote connections to get this to work? Can I get this working without doing so?

另外,如果我必须提供一个 IP 地址,有没有办法以编程方式确定该地址应该是什么?

Also, if I have to provide an IP address, is there a way to work out what that address should be programmatically?

推荐答案

你可以试试 Data Source=host.docker.internal 前面提到的 此处.

You can try Data Source=host.docker.internal as mentioned here.

这篇关于如何从 Linux Docker 容器连接到本地 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆