简体   繁体   中英

Couldn't connect to MS SQL Server docker container from another docker container

I have pulled and run SQL Server 2017 container image using the following command:

docker run --name mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=123456789aBcD" -e"MSSQL_PID=Express" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-CU14-ubuntu-20.04

Then i wrote new config string for my app:

{
  "ConnectionStrings": {
    "DbConspectConfig": "Server=mysql;Database=Test;User Id=sa;Password=123456789aBcD"
  }
}

Then i just started my app with this conditions in the Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["EASI.Conspect/EASI.Conspect.csproj", "EASI.Conspect/"]
RUN dotnet restore "EASI.Conspect/EASI.Conspect.csproj"
COPY . .
WORKDIR "/src/EASI.Conspect"
RUN dotnet build "EASI.Conspect.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "EASI.Conspect.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EASI.Conspect.dll"]

but afterwards i have this error:

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: 35 - An internal exception was caught)

What i need to do to fix this problem?

Don't run your workloads on the default bridge network if you need DNS resolution. Containers on the default bridge network can only access each other by IP addresses, unless you use the --link option, which is considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM