Connect to SQL Server in local machine (host) from docker using host.docker.internal

旧巷老猫 提交于 2019-12-22 01:18:11

问题


I'm trying to connect to my SQL Server instance running in my local computer using host.docker.internal (as recommended in https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds)

The host.docker.internal is successfully resolved to an IP, and it's ping-able

And I've opened up the port 1433 in my firewall configuration

Error message

Connection refused 192.168.65.2:1433

My connection string

Data Source=host.docker.internal,1433;Initial Catalog=;Persist Security Info=False;User ID=;Password=;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

docker version

Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:12:48 2018
 OS/Arch:      windows/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:22:38 2018
  OS/Arch:      linux/amd64
  Experimental: true

Docker for windows version


回答1:


If anyone have similar problem, here's how I solve it

  • Open SQL Server Configuration Manager
  • Enable TCP/IP in Server Network Configuration
  • Restart SQL Service Service

If it's still not working, there are a few more things to check

  1. Firewall (open port 1433)
  2. Enable remote connections to your sql server



来源:https://stackoverflow.com/questions/50166869/connect-to-sql-server-in-local-machine-host-from-docker-using-host-docker-inte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!