繁体   English   中英

无法从另一个 docker 容器连接到 MS SQL 服务器 docker 容器

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

我使用以下命令提取并运行 SQL Server 2017 容器映像:

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

然后我为我的应用程序编写了新的配置字符串:

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

然后我刚刚在 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"]

但之后我有这个错误:

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)

我需要做什么来解决这个问题?

如果您需要 DNS 分辨率,请不要在默认桥接网络上运行您的工作负载。 默认桥接网络上的容器只能通过 IP 地址相互访问,除非您使用 --link 选项,该选项被视为旧版。 在用户定义的桥接网络上,容器可以通过名称或别名相互解析。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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