2

We can create a new container and define your application port in docker run command like

sudo docker run -d -p 5000:5000 training/webapp python app.py

or

sudo docker run -d -P training/webapp python app.py

But, what if someone forgot to specify -p or -P option in docker run command? The container get created and runs the application locally. Now how could I assign a port on which application is running locally in container to the port of my Ubuntu host machine? Kindly, help on this. Thanks.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
  • possible duplicate of [Exposing a port on a live Docker container](http://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container) – Hardy Sep 05 '14 at 13:03

1 Answers1

0

Short: You can't. You need to stop the container (or not) and start a new one with the proper parameters.

Docker spins up a local proxy and setup the iptables for proper NAT. If you really can't start a new container, you could manually setup the iptables and spin up a socat. You can take a look at the network part of the Docker code for more info.

creack
  • 116,210
  • 12
  • 97
  • 73