I am running Sql Server on a container. I have set up the docker-compose and all services are able to connect to the database in order to perform design time entity framework core migrations.
I would like to connect to the database from the host machine. This does not appear to work with the following code (using "port"). I get
"
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
The network path was not found
"
docker-compose yaml file:
version: '3.4'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
container_name: sqlservice
ports:
- 1433:1433
etc...
Any ideas greatly appreciated.
Thanks paulsm4
The link to the ms docs gives the answer:
ANSWER: Use the IP Address of the local machine See https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-2017
Find the IP address for the machine that hosts your container. On Linux, use ifconfig or ip addr. On Windows, use ipconfig.
Run sqlcmd specifying the IP address and the port mapped to port 1433 in your container. In this example, that is the same port, 1433, on the host machine. If you specified a different mapped port on the host machine, you would use it her
(I was using 0.0.0.0, and also tried the IP address given by docker inspect - both of these failed)