[英]docker: cannot map two container ports to one host port
app.json for pm2 (src/app.py is Flask app): pm2的app.json(src / app.py是Flask应用):
{
"apps": [
{
"exec_mode": "fork",
"script": "src/app.py",
"args": ["-p", "8080"]
},
{
"exec_mode": "fork",
"script": "src/app.py",
"args": ["-p", "8081"]
}
]
}
~
Dockerfile: Dockerfile:
EXPOSE 8080 8081
CMD ["pm2", "start", "app.json"]
Error when running docker: 运行docker时发生错误:
docker run -p 8080:8080 -p 8080:8081 oct20
docker: Error response from daemon: driver failed programming external connectivity on endpoint high_fermi (xxxxxxxxxxx): Bind for 0.0.0.0:8080 failed: port is already allocated.
Any ideas? 有任何想法吗? Thanks 谢谢
You can't have two things listening on one port in the host - whether they're separate ports in one container, or two Docker containers, or two other apps. 您无法在主机上的一个端口上监听两件事–无论它们是一个容器中的单独端口,还是两个Docker容器中的端口,还是两个其他应用程序中的端口。 It's not a Docker limitation, it's part of the OS networking stack. 这不是Docker的限制,它是OS网络堆栈的一部分。
Where would the host send a request to port 8080 if you could do that in this case? 在这种情况下,主机可以在哪里将请求发送到端口8080? To port 8080 in the container, or port 8081, or multicast it to both? 要在容器中使用端口8080,还是使用端口8081,或将其多播到两者?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.