简体   繁体   English

docker:无法将两个容器端口映射到一个主机端口

[英]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.

相关问题 Docker Mac Beta和容器是否连接到主机端口? - Docker Mac Beta and container connecting to host ports? 检索从 Docker SDK for Python 启动的容器的主机端口 - Retrieve the host port, of a container launched from Docker SDK for Python Docker 容器端口设置不正确 - Docker container ports setup incorrectly 在一个容器中运行两个服务 Docker - Run Two Services in One container Docker 在停止docker-container之前,复制一个文件并存储到主机 - Before stopping the docker-container copy one file and store to the host 在 Docker 中为 Python 容器公开端口 - Expose port in Docker for Python container 如何为我的 Flask 应用程序从 Elastic Beanstalk 到我的 Docker 容器的端口 map? - How can I map a port from Elastic Beanstalk to my Docker container for my Flask app? 无法从我的 docker 容器连接到远程数据库实例,但是可以从我的主机连接 - Cannot connect to remote Database instance from my docker container, however can connect from my host computer 如何在 docker 和 python 的不同端口中托管应用程序 - How to host app in different port in docker and python 使用简单的python tcp脚本连接同一台主机上的两个Docker容器,但出现连接被拒绝的错误 - Use a simple python tcp script to connect two Docker container on the same host machine but got Connection refused error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM