gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:07:29 34 4
gpt4 key购买 nike

我正在尝试在本地计算机上的 docker 容器内测试我的应用程序的发布版本,当我启动容器时,我不断收到以下警告,它拒绝了请求:

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.

我检查过 this post ,这不是问题所在,我也无法找到问题的根本原因。当我提出要求时,他们被拒绝了。该应用程序可以在 Docker 之外正常运行。下面是我的 dotnet publish 命令:

dotnet publish .\Sistema.Cadastro.Api\Sistema.Cadastro.Api.csproj -c Release --runtime linux-musl-x64 --interactive --no-self-contained

发布后,我生成我的容器。下面是我的 Dockerfile

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
EXPOSE 5000
EXPOSE 5001

COPY System.Cadastro.Api/bin/Release/netcoreapp3.1/linux-musl-x64/publish/ /app
WORKDIR /app
ENTRYPOINT ["dotnet", "Sistema.Cadastro.Api.dll"]

构建容器后,我使用下面的 docker-compose.yaml 启动它:

version: '3'

services:
siefcadapi:
container_name: sistemacadapi
image: localdocker/sistema.cadastro.api:latest
ports:
- 5000:5000
- 5001:5001
environment:
- "ASPNETCORE_URLS=https://+:5001;http://+:5000"

下面是生成的日志:

docker-compose -f .\.docker\docker-compose.yaml up
Recreating sistemacadapi ... done
Attaching to sistemacadapi
sistemacadapi | warn: Microsoft.AspNetCore.Server.Kestrel[0]
sistemacadapi | Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
sistemacadapi | info: Microsoft.Hosting.Lifetime[0]
sistemacadapi | Now listening on: http://localhost:5000
sistemacadapi | info: Microsoft.Hosting.Lifetime[0]
sistemacadapi | Application started. Press Ctrl+C to shut down.
sistemacadapi | info: Microsoft.Hosting.Lifetime[0]
sistemacadapi | Hosting environment: Production
sistemacadapi | info: Microsoft.Hosting.Lifetime[0]
sistemacadapi | Content root path: /app

我不需要在容器内部进行调试,也不需要进行任何类似的调试。我只想运行和测试我的应用程序,以便我可以推送到 Azure 在云端运行。

最佳答案

经过2天的挖掘,我发现了问题。一点都不明显。我使用 appsettings.json,并使用模型读取它,并将其注入(inject)到 Startup.cs

的 IConfiguration 中
    var appConfigs = Configuration.GetSection("App").Get<AppConfigs>();

services.AddSingleton<IConfiguration>(Configuration);

破坏所有内容的是第二行:

    services.AddSingleton<IConfiguration>(Configuration);

根据 this answer , .net core 2之后就不用加了。添加它并没有在调试过程中搞砸,但是一旦它在容器中运行,它就会导致上面列出的错误。我刚刚删除了第二行,应用程序仍然运行良好,并且它在容器内也开始完美运行。

Creating projeto_sistemacadastroapi_1 ... done
Attaching to projeto_sistemacadastroapi_1
sistemacadastroapi_1 | info: Microsoft.Hosting.Lifetime[0]
sistemacadastroapi_1 | Now listening on: http://[::]:80
sistemacadastroapi_1 | info: Microsoft.Hosting.Lifetime[0]
sistemacadastroapi_1 | Application started. Press Ctrl+C to shut down.
sistemacadastroapi_1 | info: Microsoft.Hosting.Lifetime[0]
sistemacadastroapi_1 | Hosting environment: Production
sistemacadastroapi_1 | info: Microsoft.Hosting.Lifetime[0]
sistemacadastroapi_1 | Content root path: /app

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

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com