Docker Windows Container API with EFCore connecting to microsoft/mssql-server-windows-developer container

I’ve got 2 windows containers for:

  1. MSSQL Server Developer Edition (microsoft/mssql-server-windows-developer)
  2. Asp.Net Core API 5.0 (5.0.102) (solomiosisante/consequence:api)

No problem accessing the SQLServer container data from Management Studio (SSMS).

No problem when I run the API project from Visual Studio accessing the SQLServer container.

The problem is when I run both containers, the error says:

fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]

An error occurred using the connection to database ‘Consequence’ on
server ‘localhost,14344’.

fail: Microsoft.EntityFrameworkCore.Query[10100]

An exception occurred while iterating over the results of a query for
context type ‘Consequence.EF.Models.ConsequenceContext’.

Microsoft.Data.SqlClient.SqlException (0x80131904): 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: TCP Provider, error: 0 – No
connection could be made because the target machine actively refused

SQL Server Container:

The SQL Container came from the image I built using microsoft/mssql-server-windows-developer. I attached my db and created an image and uploaded it to my docker hub existing repo solomiosisante/consequence:sqlexpress. I used the sqlexpress image before, thus the tagname :sqlexpress. I’ve yet to change it to :developer.

API Dockerfile:

FROM AS base

FROM AS build
COPY ["Consequence.API/Consequence.API.csproj", "Consequence.API/"]
RUN dotnet restore "Consequence.API/Consequence.API.csproj"
COPY . .
WORKDIR "/src/Consequence.API"
RUN dotnet build "Consequence.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Consequence.API.csproj" -c Release -o /app/publish

FROM base AS final
COPY --from=publish /app/publish .

ENV ASPNETCORE_URLS="https://+;http://+" 
ENV ASPNETCORE_Kestrel__Certificates__Default__Password="[email protected]" 
ENV ASPNETCORE_Kestrel__Certificates__Default__Path=/src/certs/consequence.pfx

ENTRYPOINT ["dotnet", "Consequence.API.dll"]

Build and Run Scripts:

SQL Container:

docker run --name=sqlserver-container -d -p 14344:1433 -e [email protected] -e ACCEPT_EULA=Y solomiosisante/consequence:sqlexpress

ASP.Net Core 5.0.102:

dotnet dev-certs https -ep certsconsequence.pfx -p [email protected]
dotnet dev-certs https --trust
docker build --pull -t consequenceapi:latest --file Consequence.API/Dockerfile .
docker run -d -p 8088:80 -p 44388:443 -v C:SolRepoConsequencecerts:C:srccerts --name consequenceapi  consequenceapi:latest

Dockerhub repo for API: solomiosisante/consequence:api

I’ve read about docker network and tried all sorts. Still no luck. I’m hoping that this is not because I’m using Windows containers and that is one of the limitations of using it.

Any ideas, comments, thanks in advance.

Source: Docker Questions