Docker, MS SQL Server, SMMS not connecting unless I stop any local SQL Server Instance

365 views Asked by At

I'm trying to connect to SQL Server in a docker container via SQL Server Management Studio.

My docker SQL container instance is running with the following command:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Pizza1234$" -p 1433:1433 --name sqlserver-test -d mcr.microsoft.com/mssql/server:2017-latest

I then try to connect to the SQL Server in the docker container using the server name: localhost, 1433

I was unable to connect SSMS to the instance of SQL Server in the sqlserver-test container but then discovered that if I stop my local instance then SSMS will connect to the SQL server instance in docker which would suggest that SQL is attempting to find a local localhost instance and only when it cannot find one it points to the one docker is hosting.

Can I explicitly set a name for the docker instance or can I include an IP address in the server name when trying to connect to the instance in docker via ssms? I can connect when both are running via bash run from docker so I think it is something missing from my server name when using SSMS.

1

There are 1 answers

0
Stefano On BEST ANSWER

change the mapped port on the host and you should be good to go. The 2 instances are trying to get hold of the port 1433 and only the first will manage to be satisfied.

You can replace the -p 1433:1433 with -p 2434:1433 and change the connection string on the client.