- I have an ASP-NET core windows container on my docker desktop for Windows. The dockerfile and docker-compose file are created by Visual Studio by default.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY [“AspNetCore1/AspNetCore1.csproj”, “AspNetCore1/”]
RUN dotnet restore “AspNetCore1/AspNetCore1.csproj”
COPY . .
RUN dotnet build “AspNetCore1.csproj” -c Release -o /app/build
FROM build AS publish
RUN dotnet publish “AspNetCore1.csproj” -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
COPY --from=publish /app/publish .
ENTRYPOINT [“dotnet”, “AspNetCore1.dll”]
I can ping outside websites from within the container, so the container’s networking including its DNS is fine.
My container’s public IP address is the same as my host PC. When I ran the ASP-NET core app on my host PC, it can connect to and query the AWS RDS database without any problem. So the AWS database and its accessibility such as security groups etc. is not the problem.
However, when I ran the asp-net core app in the container, it can’t connect to the AWS RDS database:
Microsoft.Data.SqlClient.SqlException: ‘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)’
It appears to me that the container itself specifically disallows SQL Server connections. Please help!