How to connect to the database from host - sql server in container running under docker compose

containers docker-compose entity-framework-core migration port


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'
        container_name: sqlservice
          - 1433:1433

Any ideas greatly appreciated.

12/14/2018 10:24:26 PM

Accepted Answer

Thanks paulsm4

The link to the ms docs gives the answer:

ANSWER: Use the IP Address of the local machine See

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, and also tried the IP address given by docker inspect - both of these failed)

12/14/2018 10:21:18 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow