Docker Quick Start series (5): basic network configuration and communication during storage, docker Quick Start
Introduction
Two major functional modules that are essential for a web service to run: business processing, data services, and large web services require more components, which usually requires multiple containers, however, we also need to allow network communication between these containers and cooperate with each other.
Currently, Dokcer only supports communication between host machines and containers.
Port ing between host and container
When you start a container, if no corresponding parameter is specified, you cannot access network applications and services in the container outside the container.
To allow external access to some network applications in the container, you can use the-p or-p parameters to define port ing. When the-p Flag is used, Docker will map a 49000 ~ Port 49900 to the network port developed inside the container:
# I don't know why the container does not map ports after I-P here, but the official example can be used.
The second method is to create a port ing relationship for the container:
Map multiple mappings at the same time:
Port ing of the specified address:
Map any port of the specified address:
Port ing between containers and containers
In addition to port ing, the container connection system can interact with applications in the container. It creates a tunnel between the source and the receiving container, and the receiving container can see the information specified by the container.
Custom container name
The Connection System is executed based on the container name. Therefore, you must first customize a memorable container name.
Although a name is assigned by default when a container is created, the custom naming container has two advantages:
1. The custom name is easy to remember. For example, for a web application container, We can name it web
2. When connecting to other containers, it can be used as a useful reference, such as connecting web containers to db containers.
You can use the-name tag to customize the container name:
docker run -d -P -name web ubuntu:nodejs
You can also useDocker inspectTo view the container Name:
docker inspect -f "{{.Name}}" CONTAINER_ID
The-link parameter allows secure 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 be connected, and alias is the alias of the connection.