0

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
  • 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

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?

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

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
  • are running sql server on docker container on windows machine or is it like you want to connect to local instance of sql server running on windows from a docker container running on windows – TheGameiswar Aug 23 '17 at 10:05
  • I am running SQL Server on my Windows machine and want to connect to it from a Docker container. – Muhammad Rehan Saeed Aug 23 '17 at 10:08
  • I think you have figured out it `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?` – TheGameiswar Aug 23 '17 at 10:09
  • 1
    IF you are on same host,then no need of enabling remote connections ,other wise you will need to enable,try enabling remote connections and check if it resolves the issue – TheGameiswar Aug 23 '17 at 10:10
  • 1
    Did you try running your container with `--net=host` option? – Tarun Lalwani Aug 23 '17 at 14:52
  • @TarunLalwani That is a very good idea. I'm using Docker support for Visual Studio, so I've raised this issue https://github.com/Microsoft/DockerTools/issues/40 – Muhammad Rehan Saeed Aug 23 '17 at 16:13
  • 1
    A very detailed answer has been written here: https://stackoverflow.com/a/24326540/3025545 – Kh.Taheri Sep 21 '17 at 06:56

1 Answers1

0

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

dalenewman
  • 1,234
  • 14
  • 18