Home >Operation and Maintenance >Docker >How docker sets port mapping for running containers
Method 1:
1. Obtain the container IP
Replace container_name with the container name in the actual environment
docker inspect `container_name` | grep IPAddress
2 , iptable forward port
Map the 8000 port of the container to the 8001 port of the docker host
iptables -t nat -A DOCKER -p tcp --dport 8001 -j DNAT --to-destination 172.17.0.19:8000
Method 2:
1. Submit a running container as a mirror
docker commit containerid foo/live
2. Run the image and add the port
docker run -d -p 8000:80 foo/live /bin/bash
Recommended tutorial: docker tutorial
The above is the detailed content of How docker sets port mapping for running containers. For more information, please follow other related articles on the PHP Chinese website!