Why serve something port mapping.
When you start the container, if you do not configure port mappings between the host machine and the virtual machine, the external program cannot access the virtual machine because there is no port.
What is the directive for port mapping.
Docker command: Docker run-p ip:hostPort:containerPort Redis
Use the-p parameter to map the host's port to the virtual machine.
IP represents the IP address of the host.
The hostport represents the port of the host.
Containerport represents the port of the virtual machine.
There are three types of supported formats:
Ip:hostPort:containerPort: Maps the specified port of the specified address to the specified port of the virtual machine (not commonly used)
For example: 127.0.0.1:3306:3306, map the 3306 port of this machine to the 3306 port of the virtual machine.
Ip::containerport: Maps Any port of the specified address to the specified port of the virtual machine. (not commonly used)
For example: 127.0.0.1::3306, map the 3306 port of this machine to the 3306 port of the virtual machine.
Hostport:containerport: Maps the specified port of this machine to the specified port of the virtual machine. Common
For example: 3,306:3,306, map the 3306 port of this machine to the 3306 port of the virtual machine.
How to see if the mapping was successful.
Use the Docker PS command to view
A 6379/tcp appears that hosts the host and does not have port mappings open to the virtual machine.
The presence of 0.0.0.0:3306->3306/TCP indicates that the 3306 port of the host is mapped to the 3306 port of the virtual machine.
You can also use Docker port name to view the port mapping situation.
Indicates that the 3306 port of the virtual machine is mapped to the 3306 port of the host.
If there is no reply, the port mapping fails.