您正在(运行)一个 docker-image ..并且(正在运行)docker-image 不理解连接字符串,例如
localhost
localhost\MyInstance
您需要 docker-running-image 才能与您的本地设置进行对话。您可以使用本地计算机的 IP 地址。但幸运的是,docker 有一个内置的 ALIAS,用于“生成我的主机(docker 镜像)”。
see:
https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
我想从容器连接到主机上的服务 主机
有一个不断变化的 IP 地址(如果您没有网络访问权限,则没有 IP 地址)。我们
建议您连接到特殊的 DNS 名称
host.docker.internal 解析为使用的内部 IP 地址
主人。这是出于开发目的,不适用于
Docker Desktop 之外的生产环境。
下面显示了该别名,以及如何将其用于 Ms-Sql-Server 连接字符串。
数据源=host.docker.internal:1433;DatabaseName=MyDatabase;
or
“服务器=主机.docker.internal\MyInstance;数据库=MyDatabase;”
您可能还需要使用 sql 身份验证,以“从 docker”跳转到本地计算机。 (docker-running-image不会理解本地开发人员对集成安全性的理解中的“集成安全性”)
您必须将运行映像的 docker 视为另一台机器,因此如果您有 localhost\MyInstance sql 服务器,则还必须打开到它的远程 tcp 连接。
一般经验法则。
在您的计算机上运行的容器...不像本地代码...当它
涉及诸如 db-server、local-sftp 等之类的东西。
如果您不使用 sql-authentication,您可能会收到如下错误:
Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication.
ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: GSSAPI operation failed with error - Unspecified GSS failure. Minor code may provide more information (SPNEGO cannot find mechanisms to negotiate).
BONUS:
下面是我添加了书签的文章,用于允许远程连接到您的本地计算机。
https://knowledgebase.apexsql.com/configure-remote-access-connect-remote-sql-server-instance-apexsql-tools/ https://knowledgebase.apexsql.com/configure-remote-access-connect-remote-sql-server-instance-apexsql-tools/