Docker Community Forums

Share and learn in the Docker community.

Can a .net core 3.1 app that is containerized in linux connect to SQL server 2016 database on the network?

We have a .net core app that will be containerized on linux. I want to know how we can make this app talk to the SQL server 2016 over the network.

Just like you would if the app wasnt in a container, the container still has access to the local network to communicate with other services

Thank you @terpz. I tried to connect to the SQL server 2017 on the network from my container and receive the below error. the sql.open() when encountered in the code just hangs. I am using the “using” block for sql connection and made sure the sql connection is not left open.
The error is:

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: 40 - Could not open a connection to SQL Server)

and my Dockerfile looks like:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS base
WORKDIR /app

EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
WORKDIR /src
COPY [“EmployeeManagement/EmployeeManagement.csproj”, “EmployeeManagement/”]
RUN dotnet restore “EmployeeManagement/EmployeeManagement.csproj”
COPY . .
WORKDIR “/src/EmployeeManagement”
RUN dotnet build “EmployeeManagement.csproj” -c Release -o /app/build

FROM build AS publish
RUN dotnet publish “EmployeeManagement.csproj” -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT [“dotnet”, “EmployeeManagement.dll”]

Any help is appreciated.