docker: cannot map two container ports to one host port

app.json for pm2 (src/app.py is Flask app):

{
    "apps": [
    {
      "exec_mode": "fork",
      "script": "src/app.py",
      "args": ["-p", "8080"]
    },
    {
      "exec_mode": "fork",
      "script": "src/app.py",
      "args": ["-p", "8081"]
    }
  ]
}
~        

Dockerfile:

  • How to change the version of Ruby in a Docker image (replace 2.2.0 with 2.0.0 )
  • Run multiple servers from a docker image
  • debugging tornado server in docker container
  • Why does running docker with ProcessBuilder cause a hang?
  • Equivalent builds don't behave the same
  • docker-exec failed: “cd”: executable file not found in $PATH
  • EXPOSE 8080 8081
    CMD ["pm2", "start", "app.json"]
    

    Error when running 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

  • Redis+Docker+Django - Error 111 Connection Refused
  • How can I build a Docker Image without accessing the Docker Hub or External Sites?
  • Docker container not starting when connect to postgresql external
  • Run AspNet Core app in docker using GMSA
  • Docker-compose depend_on
  • Accessing Environment Variables in a linked Docker
  • One Solution collect form web for “docker: cannot map two container ports to one host port”

    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. It’s not a Docker limitation, it’s part of the OS networking stack.

    Where would the host send a request to port 8080 if you could do that in this case? To port 8080 in the container, or port 8081, or multicast it to both?

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.