BAE BAE - 1 year ago 106
Python Question

docker: cannot map two container ports to one host port

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

"apps": [
"exec_mode": "fork",
"script": "src/",
"args": ["-p", "8080"]
"exec_mode": "fork",
"script": "src/",
"args": ["-p", "8081"]


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 failed: port is already allocated.

Any ideas? Thanks

Answer Source

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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download