本文介绍了dotnet 核心 docker 容器 - 无法在 IPv6 环回接口上绑定到 https://localhost:5001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 .NET core 创建了一个镜像:

I created an image for .NET core:

FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

EXPOSE 80 443 5000 5001 5010 5011 7000 22676

#ENTRYPOINT [ "bash"]
CMD ["bash"]

我从中运行一个容器docker container run -it --publish 5000:8018 --name versie3001 -v//c/tijd/mount:/app michel03

一切顺利的是我看到了挂载的文件.当我使用 dotnet new razor 创建一个新网站并使用 dotnet run 运行它时,它尝试在端口 5000/5001(默认端口)上运行,但出现此错误:

What goes well is that I see the mounted files.When I create a new website with dotnet new razor and I run it with dotnet run it tries to run on port 5000/5001 (default ports) but I get this error:

warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.

其实它说的是warn,但结果是一样的,当我去localhost:8018 时我没有得到任何结果(ERR_CONNECTION_REFUSED)

Actually it says warn, but the result is the same, when I go to localhost:8018 I get no result (ERR_CONNECTION_REFUSED)

我在这里做错了什么?

我看到一个回答说我应该在我的容器文件中这样做:ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "https://0.0.0.0:5000"].它没有给我错误(输出是 Now listen on: https://0.0.0.0:5000),这很好,但它也没有从 https://连接localhost:8018 在我的本地机器上.

I saw an answer saying I should do this in my containerfile:ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "https://0.0.0.0:5000"]. It does not give me the error (output is Now listening on: https://0.0.0.0:5000), which is good, but it also does not connect from https://localhost:8018 on my local machine.

推荐答案

你的 --publish 选项是向后的:它是 -p :,因此对于您的设置,您需要 --publish 8018:5000.

Your --publish option is backwards: it's -p <hostPort>:<containerPort>, so for your setup you'd want --publish 8018:5000.

抛开启动问题不谈,您确实需要选择使容器侦听 0.0.0.0(或 ::0,如果 IPv6 有效).如果它绑定到本地主机,它将无法从其容器外部访问,包括其他容器和主机.

Startup issues aside, you do need the option to cause the container to listen on 0.0.0.0 (or ::0, if IPv6 works). If it binds to localhost it will be unreachable from outside its container, including from other containers and from the host.

这篇关于dotnet 核心 docker 容器 - 无法在 IPv6 环回接口上绑定到 https://localhost:5001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:32