When the container is generally run, we will parameter -p (an uppercase -P parameter is randomly select a port mapping host computer) to specify the mapping of the host port and the container, e.g.
docker run -it -d --name [container-name] -p 8088:80 [image-name]
This is mapped to a port 80 in the container port of the host 8088
Parameter Description
- -d represents the background container
- -t on a pseudo-terminal is assigned and bound to container docker standard input
- -i is to get a container of standard input remains open
- -p port specify the mapping
After specifying the port mapping operation when running the container, if you want to add a new port mapping, can be used in two ways:
A way : The existing container packaged into mirror, then re-specify the port to be mapped during operation of the new image container
Probably as follows:
Stop existing containers
docker stop container-name
The vessel commit be a mirror
docker commit container-name new-image-name
Mirror operation with the new container
docker run -it -d --name container-name -p p1:p1 -p p2:p2 new-image-name
Second way : to modify the container port mapping configuration file
View container information :
docker ps -a
View container port mapping , the execution outside the container:
docker port container vessel docker port name or ID
Find Id container vessel to be modified
docker inspect f244 |grep Id
Advance to the next / var / lib / docker / containers directory to find the Id in the same directory, and modify hostconfig.json config.v2.json file :
If the container is still running, first stopped
Container ID docker stop
Service stopped docker
systemctl stop docker
Hostconfig.json modified as follows, adding port binding "9003 / TCP" : [{ "HOSTIP": "" , "the HostPort": "9003" }], represents a binding port 9003
Modify config.v2.json in ExposedPorts plus be exposed in ports, namely 9003
After they started saving docker
systemctl start docker
After you have added the port has been re-mapped binding on
NOTES:
1, the packaging container are mirror images of command:
the commit -a Docker " King Xiyanghe " -m "A new new Image " [name or ID container] [image name packaged]: [tab]
Common OPTIONS Description:
- -a: Mirror of submission
- -c: Use Dockerfile command to create a mirror
- -m: caption when submitted
- -p: When commit, the container is suspended
2, the host port to see whether the container port mapping successfully performed outside the container
-an netstat | grep host port mapping
If there exists a mapping process is expressed