2

Orchestration:

  • Windows Host
  • My DB is running in a container on localhost:1444.
  • My API is running in a container on localhost:5000/5001.
  • They are both running on the default (bridge) network.
  • I can't use a custom network because currently our app references another API that is not in a container

At first I just left the connection string as .,1444 but realized that the container would have to look up outside of itself to get the host localhost it needed.

So far I've tried:

  • 127.0.0.1:1444
  • host.docker.internal:1444
  • 127.0.0.1,1444
  • host.docker.internal,1444
  • .,1444

I keep getting this error:

     Connection id "0HLV8EI9HSV9D", Request id "0HLV8EI9HSV9D:00000009": An unhandled exception was thrown by the application.
System.Data.SqlClient.SqlException (0x80131904): 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)```


jameseg
  • 730
  • 1
  • 4
  • 19
  • What "kind" of Docker is it – the Docker Desktop application or Docker Toolbox? I would expect `host.docker.internal` to work. – David Maze Apr 24 '20 at 20:16
  • @DavidMaze I updated to reflect it's Desktop - and yeah that's what I thought too. I must be missing something – jameseg Apr 24 '20 at 20:18

1 Answers1

1

The most common way to do this is to add --network="host" in your docker run command, then 127.0.0.1 in your docker container will point to your docker host.

If this is not suitable for you, this question contains a bunch of hacky ways to achieve the same thing.

Such as:

  • Mapping the local IP alias name (DNS) in the container
  • Volume mounting certain files for communication purposes
  • Enabling route_localnet for docker0 interface

I believe that link will help you come to a solution that is most suitable for you.

Brand
  • 347
  • 2
  • 11