简体   繁体   English

Docker windows 端口不可用:

[英]Docker windows Ports are not available:

New to Docker. Docker 的新手。 I am running Visual Studio 2019 community on Win 10 machine.我在 Win 10 机器上运行 Visual Studio 2019 社区。 Installed Docker desktop and created two solutions (service1 and service2).安装 Docker 桌面并创建两个解决方案(service1 和 service2)。 I am trying to run both of the solutions on their own containers.我正在尝试在它们自己的容器上运行这两个解决方案。

I was able to build and run service1 using:我能够使用以下方法构建和运行 service1:

docker run -it --rm -p 3000:80 --name mymicroservicecontainer mymicroservice

Question what is 3000:80?提问3000:80 是什么? is 80 a port? 80是一个端口吗? because I was able to run my api using http://localhost:3000/api/product/1 from browser.因为我能够使用http://localhost:3000/api/product/1从浏览器运行我的 api。

Next, I am trying to run service2 on it's own container by:接下来,我试图通过以下方式在它自己的容器上运行 service2:

docker run -it --rm -p 2000:80 --name myanotherservicecontainer myanotherservice

Since the port is 2000, I guess it should work however I get following error:由于端口是 2000,我想它应该可以工作,但是我收到以下错误:

docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:2000: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

time="2020-04-08T14:22:41-04:00" level=error msg="error waiting for container: context canceled" time="2020-04-08T14:22:41-04:00" level=error msg="error waiting for container: context cancelled"

Is that because I have:80 same as service1?那是因为我有:80 与 service1 相同吗? What is the solution?解决办法是什么? I am running commands on admin mode in command prompt.我在命令提示符下以管理员模式运行命令。

Please help.请帮忙。 Thank you.谢谢你。

docker run -it --rm -p 3000:80 --name mymicroservicecontainer mymicroservice

Answer to your first question is YES , 80 is a port.第一个问题的答案是YES , 80 是一个端口。 Basically what -p 3000:80 does is that it maps TCP port 80 in the container to port 3000 on the Docker host.基本上-p 3000:80所做的是将容器中的 TCP 端口 80 映射到 Docker 主机上的端口 3000。

The error you are getting for services is because port 2000 is occupied some other process.您收到的服务错误是因为端口 2000 被其他进程占用。 It's clearly mentioned in the error message as well.错误消息中也清楚地提到了这一点。

docker: Error response from daemon: Ports are not available

If you try to map it to some other port(that is free on your machine), then it would work as expected.如果您尝试将 map 连接到其他端口(在您的机器上是免费的),那么它将按预期工作。

Maybe try -p 1111:80 or -p 1234:80也许尝试-p 1111:80-p 1234:80

Readthis for more detail on docker container networking.阅读本文以了解有关 docker 容器网络的更多详细信息。

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

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