expose a port on a living Docker container

if you have a container that with something running on its port 8000, you can run

wget http://container_ip:8000

To get the container′s ip address, run the 2 commands:

docker ps

docker inspect container_name | grep IPAddress

Internally, Docker shells out to call iptables when you run an image, so maybe some variation on this will work.

to expose the container's port 8000 on your localhosts port 8001:

iptables -t nat -A DOCKER -p tcp --dport 8001 -j DNAT --to-destination 172.17.0.2:8000

 

posted on 2017-09-22 15:39  jessezeng  阅读(344)  评论(0编辑  收藏  举报

导航