Ruan
Ruan

Reputation: 4283

How do you connect to a local SQL Server DB from within a docker container?

This question has already been asked here, but no one has answered it (also asked here without any answers). I'd like to try to get it answered.

I have a Linux Docker Image containing a console app that connects to a local DB instance. DB is on my local PC and not in the docker image

Local server Name : RIXS\RSERVER

Connection String : optionsBuilder.UseSqlServer(@"Server=RIXS\RSERVER;Database=MyTable1;Trusted_Connection=True;MultipleActiveResultSets=true");

I've tried Adding the docker image to my SQL Servername

  1. dac7889b09b0\RIXS\RSERVER

  2. dac7889b09b0\RSERVER

But I'm obviously doing something wrong. Any idea?

Upvotes: 1

Views: 2775

Answers (1)

yamenk
yamenk

Reputation: 51768

Start the container with network mode as host.

docker run --network=host ...

The host mode will make the container share the network interfaces of the host. Thus an address of localhost or 127.0.0.1 inside the container will refer to the host machine.

Upvotes: 1

Related Questions