Skip to content

Latest commit

 

History

History
21 lines (20 loc) · 779 Bytes

16.expose_port_of_a_running_container.md

File metadata and controls

21 lines (20 loc) · 779 Bytes

Source:

Example:

Launch a web-service that listens on port 80, but do not expose its internal port 80 (oops!):

docker run -ti mkodockx/docker-pastebin   # Forgot to expose PORT 80!

Find its Docker network IP:

docker inspect 63256f72142a | grep IPAddress

output

                    "IPAddress": "172.17.0.2",

Launch alpine/socat with port 8080 exposed, and get it to forward TCP traffic to that IP's port 80:

docker run --rm -p 8080:1234 alpine/socat TCP-LISTEN:1234,fork TCP-CONNECT:172.17.0.2:80

You can now access pastebin on http://localhost:8080/, and your requests goes to socat:1234 which forwards it to pastebin:80, and the response travels the same path in reverse.