SQL Server Docker Fix

In section 3.3 (for version 2.0 book), They assume that you have a SQL Server installed on the local host. In class we just used docker on your local machine and its works for the most part. However, you do need to change the connection string. Here is the process:

Bring Up a SQL Server Docker Container

# docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=ConstraintDB!23" -p 1433:1433 --name sqlserver -d mcr.microsoft.com/mssql/server:2019-latest

Now you need to adjust your connection string so change it in appsettings.json to be:

 "ConnectionStrings": {
    "sqlConnection": "Server=localhost;Database=CompanyEmployee;User Id=sa;Password=YourSecurePassword;"
  },

Problem

You try to run a SQL Server docker image with the default port (1433) and you get the following error message:

Error response from daemon: Ports are not available: listen tcp 0.0.0.0:1433: bind: An attempt was made to access a socket in a way forbidden by its access permissions. Error: failed to start containers: sqlserver

Ok, there is a simple fix for this in windows 10/11 that has worked for me in the past:

> net stop winnat
> docker start sqlserver
> net start winnat

WebServices/SqlServerDockerFix (last edited 2022-01-25 14:39:02 by scot)