我为.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
I run a container from it 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'.
实际上它说警告,但是结果是一样的,当我进入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 listening 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 <hostPort>:<containerPort>
,因此对于您的设置,您需要--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上侦听的选项(如果IPv6有效,则为:: 0).如果它绑定到本地主机,则将无法从其容器外部(包括其他容器和主机)访问该容器.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!