Introduction
A Web service is necessary to run the two major functional modules: Business processing, data services, large Web services require more components, which often require multiple containers, but we also need to be able to network communication between these containers, mutual cooperation.
Dokcer currently only supports host-to-container communication, and container-to-container communication.
Port mappings for host and container
When you start the container, if you do not specify a corresponding parameter, the network applications and services within the container cannot be accessed through the network outside the container.
When you run some network applications in the container, you can use the-p or-p parameters to make port mappings for external access to these applications. When the-p flag is used, Docker maps a 49000~49900 port randomly to a network port developed inside the container:
#不知道为什么这里我-P后容器并没有映射端口,但是官方上的样例就可以。
The second method is to set the port mapping relationship for the container:
Map multiple mapping relationships at the same time:
Port mappings for the specified address:
Map any port of the specified address:
Port mapping for containers and containers
The container's connection system is another way to interact with the application in the container, in addition to the port mapping. It creates a tunnel between the source and the receiving container, accepting that the container can see the information specified by the container
Custom container Name
The connection system executes according to the name of the container. Therefore, you first need to customize a well-remembered container name.
While creating a container, the system assigns a name by default, but there are two benefits to customizing the naming container:
1. Custom naming is good to remember, such as a Web application container, we can give it a name of the Web
2. When connecting to other containers, you can use it as a useful reference, such as connecting a Web container to a DB container.
You can use the –name tag to customize the naming for a container:
docker run -d -P -name web ubuntu:nodejs
You can also use Docker inspect to view the container's name:
"{{.Name}}" CONTAINER_ID
Use the –link parameter to allow safe interaction between containers:
docker run -d -P --name web --link db:db ubuntu:nodejs
The format of the –link parameter is –link Name:alias, where name is the name of the container to connect to, and alias is the nickname for this connection.
Docker Quick Start Series (5): Network Foundation Configuration and capacity period communication