Docker .NET 5.0 API cannot connect to external or containerd database

Viewed 178

I have this architecture on my host OS. It consist of three individual container running on my host OS (Windows 10).

dockerarchitecture

My .NET 5.0 API cannot reach my SQL Server 2019 whether my local SQL Server or containerd SQL Server.

If i run this API in VS Studio everything just works. The moment i put the image in a container if can't reach both SQL Servers...

This is my ConnectionString:

"ConnectionString": {
          "DemoDB": "server=127.0.0.1,1433;MultipleActiveResultSets=true;database=DemoDB;User ID=user;password=xxx"
    },
# Here, we include the dotnet core SDK as the base to build our app
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build-env
# Setting the work directory for our app
WORKDIR /app

# We copy the .csproj of our app to root and 
# restore the dependencies of the project.
COPY *.csproj ./
RUN dotnet restore 

# Once we're done building, we'll publish the project
# to the publish folder 
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine 
WORKDIR /app
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DemoAppBackend.dll"]

Here is my LaunchSetting.json:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:44340",
      "sslPort": 44340
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "DemoAppBackend": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

I also tried to run my docker container with the --net=host flag and accepted all inbound traffic from docker in my firewall, but this does not resolve my issue.

0 Answers
Related