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


Fact 1. 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)

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

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

Fact 4. 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 it.)

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="P@ssw0rd123" 
ENV ASPNETCORE_Kestrel__Certificates__Default__Path=/src/certs/consequence.pfx

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

I also tried:

FROM AS build
#COPY ["Consequence.API/Consequence.API.csproj", "Consequence.API/"]
#COPY ["Consequence.EF/Consequence.EF.csproj", "Consequence.EF/"]
#COPY ["Consequence.Repositories/Consequence.Repositories.csproj", "Consequence.Repositories/"]
COPY . .
RUN dotnet restore "Consequence.API/Consequence.API.csproj"

Build and Run Scripts:

SQL Container:

docker run --name=sqlserver-container -d -p 14344:1433 -e sa_password=P@ssw0rd123 -e ACCEPT_EULA=Y solomiosisante/consequence:sqlexpress

ASP.Net Core 5.0.102 Container:

dotnet dev-certs https -ep certs\consequence.pfx -p P@ssw0rd123
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:\SolRepo\Consequence\certs\:C:\src\certs --name consequenceapi  consequenceapi:latest

Dockerhub repo for API: solomiosisante/consequence:api

I also tried:

docker run -d -p 8088:80 -p 44388:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="P@ssw0rd123" -e ASPNETCORE_Kestrel__Certificates__Default__Path=\https\aspnetapp.pfx -v $env:USERPROFILE\.aspnet\https:C:\https\ --name consequenceapi  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.

Given these facts, any ideas, comments, thanks in advance.
asked on Stack Overflow Feb 9, 2021 by Sol • edited Feb 9, 2021 by Sol

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0