I set up SQL Server on Docker. I can't connect to it from my .NET Core app.
For example, when running
dotnet ef database update
I get this error
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: 35 - An internal exception was caught)
appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=myDb;User=sa;Password=reallyStrongPwd123"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
dockerfile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 1443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY testProj/TestProj.csproj TestProj/
RUN dotnet restore "testproj/TestProj.csproj"
COPY . .
WORKDIR "/src/testProj"
RUN dotnet build "TestProj.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestProj.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestProj.dll"]