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
原文地址:https://www.cnblogs.com/jessezeng/p/7575239.html