Home > other >  SQL Server named instance in Docker
SQL Server named instance in Docker

Time:11-16

How can I run a named SQL Server instance inside a Docker container?

I have an application that has a connection string pointing to a named SQL Server instance, something like Data Source=HostName\InstanceName; this connection string is very problematic for me to change. I want to dockerize that SQL Server instance. I already configured it so that I can connect to the dockerized instance via sqlcmd using sqlcmd -S HostName but when using sqlcmd -S HostName\InstanceName (which should be equivalent to the connection string this application is using) it does not establish a connection.

CodePudding user response:

Docker containers do not support named instances; this is mentioned here:

There is no concept of a named instance. Every container can have a unique name.
...
Containers don't have a concept of running multiple SQL Server instances. So there is no option of running more than one instance name.

Really, you should change the connection string. An alternative if you can't change the connection string (but you really should change the connection string) is to create an alias on each client using their local client network utility or configuration manager.

For example, you can create an alias on the client that points to HostName\InstanceName but, underneath, the mapping would actually redirect to HostName,2700 (assuming 2700 is the port you specified in docker run ... -p 2700:1433 ...).

Aliases are talked about more thoroughly here and I talk about using custom and specific ports for Docker containers here.

Did I mention it is much more logical to change your connection strings? That is probably the problem you want to fix.

  • Related