docker - 无法绑定(bind)到 http ://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'

标签 docker visual-studio-2019 c#-8.0 asp.net-core-3.1

我正在使用启用了 docker 的 asp.net core 3.1 项目模板(VS2019)来开发 Web API。没有编译错误。

运行项目时,在 VS2019 的输出窗口中,我看到以下消息:

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Security.Cryptography.OpenSsl.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Security.Cryptography.Encoding.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Runtime.Numerics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.AspNetCore.Server.Kestrel: Warning: Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
[40m[1m[33mwarn[39m[22m[49m: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
[40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
Microsoft.Hosting.Lifetime: Information: Now listening on: http://localhost:5000
[40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
Microsoft.Hosting.Lifetime: Information: Now listening on: https://localhost:5001
Microsoft.Hosting.Lifetime: Information: Application started. Press Ctrl+C to shut down.
[40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
[40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
Microsoft.Hosting.Lifetime: Information: Hosting environment: Development
Microsoft.Hosting.Lifetime: Information: Content root path: /src/QueryStack/Author.Query.New.API
[40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
      Content root path: /src/QueryStack/Author.Query.New.API

这是我的 Docker.develop 文件:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
ARG BUILD_CONFIGURATION=Debug
ENV ASPNETCORE_ENVIRONMENT=Development
ENV DOTNET_USE_POLLING_FILE_WATCHER=true    
EXPOSE 80

WORKDIR /src
COPY ["QueryStack/Author.Query.New.API/Author.Query.New.API.csproj", "QueryStack/Author.Query.New.API/"]
COPY ["QueryStack/Author.Query.Persistence/Author.Query.Persistence.csproj", "QueryStack/Author.Query.Persistence/"]
COPY ["Common/Author.Core.Framework/Author.Core.Framework.csproj", "Common/Author.Core.Framework/"]
COPY ["Common/Author.Core.Services.Rediscache/Author.Core.Services.Rediscache.csproj", "Common/Author.Core.Services.Rediscache/"]
COPY ["QueryStack/Author.Query.Domain/Author.Query.Domain.csproj", "QueryStack/Author.Query.Domain/"]
COPY ["Common/Author.Core.Services.Persistence.CosmosDB/Author.Core.Services.Persistence.CosmosDB.csproj", "Common/Author.Core.Services.Persistence.CosmosDB/"]

RUN dotnet restore "QueryStack/Author.Query.New.API/Author.Query.New.API.csproj"
COPY . .
WORKDIR "/src/QueryStack/Author.Query.New.API"
RUN dotnet build --no-restore "Author.Query.New.API.csproj" -c $BUILD_CONFIGURATION

RUN echo "exec dotnet run --no-build --no-launch-profile -c $BUILD_CONFIGURATION --" > /entrypoint.sh

ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

任何人都可以通过提供解决此问题的指导来帮助我吗

最佳答案

要解决此问题,请添加代码 ENV ASPNETCORE_URLS= http://+:80 在 Dockerfile.develop 文件顶部的其他 ENV 声明下方

Dockerfile.develop 之后:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
ARG BUILD_CONFIGURATION=Debug
ENV ASPNETCORE_ENVIRONMENT=Development
ENV DOTNET_USE_POLLING_FILE_WATCHER=true  
ENV ASPNETCORE_URLS=http://+:80  
EXPOSE 80

关于docker - 无法绑定(bind)到 http ://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59657499/

相关文章:

azure - 调试 yaml 管道脚本

postgresql - 如何使用 docker-compose 连接到 PostgreSQL?

webdeploy - 自移至VS 2019后无法发布

c# - 'nullable' 值无效 : 'Enable' for C# 7. 3

c# - 为什么显式声明的引用返回值会出现可为空警告?

c# - 我想警告编译器有关外部代码中可能存在的空值

docker - 无法在 Raspberry Pi 上运行 elasticsearch 镜像

dns - 在 mesos 集群上设置 Mesos-DNS dockerized

javascript - 使用 TypeScript 5.1 时,Visual Studio 2019 不显示完成,并且无法在 TypeScript 文件中设置断点

visual-studio-2019 - 如何防止 Visual Studio (2019) 打开 "VS Debug Console"而只使用旧的 .NET Core 主机控制台?