bucrogers / Dockerfiles-for-windows

Dockerfiles for SQL Server, ASP.NET 4.6 / IIS App, Docker Swarm, PostgreSQL, Python REST service et al.
MIT License
136 stars 56 forks source link

Access SQL Express from outside the host VM not possible #8

Open eliassal opened 7 years ago

eliassal commented 7 years ago

I have built the SQL image and it works fine and can access it from host machine through SQL studio management. I understnad that to accessed sql from outside the host machine – for a single instance of the SQL Server container, we need to open port 1433 – from powershell:

if (!(Get-NetFirewallRule | where {$_.Name -eq "SQLServer 1433"})) { New-NetFirewallRule -Name "SQL Server 1433" -DisplayName "SQL Server 1433" -Protocol tcp -LocalPort 1433 -Action Allow -Enabled True}

I ran the command and get the following error

New-NetFirewallRule : There are no more endpoints available from the endpoint

In fact, even running this simple command

Get-NetFirewallProfile

I get the same error

Thanks for your help

StefanScherer commented 7 years ago

@eliassal It is much easier to use the port mapping in the docker run command

docker run -d -v 1433:1433 sql

That will do all the mapping and firewall exceptions for you. And the firewall exceptions will be removed after the container terminates.

eliassal commented 7 years ago

Stefen, in the yml file, I already do this

services: db: image: sqlexpress2014-site environment: sa_password: "Password" ports:

  • "1433:1433"

isn'th the ame thing?

StefanScherer commented 7 years ago

Oh, yes, that's the same. Then you might face the problem accessing the SQL server on port 1433 from the Docker host machine. You need to use the IP address of the Windows container. See this blog post https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

eliassal commented 7 years ago

I have no problem accessing the sql container from the host machine; it works fine as indicated in SQL studio and from a project inside Visua studio

eliassal commented 7 years ago

I even access it by its name as follows F9FEFB7986C2\SQLEXPRESS

see snapshot sqlstudio