Docker Learning note-docker Port mapping

Source: Internet
Author: User
Tags docker ps docker run

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.