1. Customize the network to realize container interconnection
–net=bridge This is the default value, connecting to the default bridge. –net=host tells Docker not to put the container network into an isolated namespace, that is, not to containerize the network inside the container. At this point the container uses the local host's network and has full access to the local host interface. The container process can open low-range ports like other root processes on the host, access local network services such as D-bus, and allow the container to do things that affect the entire host system, such as restarting the host. Therefore use this option with caution. If --privileged=true is further used, the container will be allowed to directly configure the host's network stack. –net=container:NAME_or_ID tells Docker to put the newly created container process into the network stack of an existing container. The new container process has its own file system, process list, and resource limits, but will share network resources such as IP addresses and ports with the existing container. The two processes can communicate directly through the lo loopback interface. –net=none tells Docker to put the new container into an isolated network stack, but not to do any network configuration. Afterwards, users can configure it themselves.
# --driver bridge bridge mode# --subnet 192.168.0.0/16 subnet segment# --gateway 192.168.0.1 gateway# mynet network namedocker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet View customized network information: docker network inspect mynet
docker run -d -P --name tomcat01-net-01 --net mynet tomcat docker run -d -P --name tomcat01-net-02 --net mynet tomcat Check the custom network information again: the two newly created containers are found to be added to the network.
tomcat01-net-01 pings tomcat01-net-02: tomcat01-net-02 pings tomcat01-net-01: Now containers can ping each other without using --link, and containers can communicate with each other. 2. Network connectivity
Create two containers, tomcat01 and tomcat02: docker run -d -P --name tomcat01 tomcat docker run -d -P --name tomcat02 tomcat Obviously, it is impossible to ping directly. You need to connect the tomcat01 container to the mynet network first.
The docker network connect command is used to connect a docker container to a network. You can use the container name or container ID. usage: docker network connect [OPTIONS] NETWORK CONTAINER Connect the tomcat01 container to the mynet network: docker network connect mynet tomcat01 View the network information of mynet: docker inspect mynet tomcat01 is already connected to the mynet network, as are tomcat01-net-tomcat01 and tomcat01-net-tomcat02. At this point, tomcat01 has been connected to the two containers in the mynet network. Since the three containers are in the same network, they can of course communicate with each other:
View the metadata of tomcat01: docker inspect tomcat01 After tomcat01 is connected to the custom mynet network, there are two networks. This is the end of this article about custom network implementation in Docker. For more relevant Docker network content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL index principle and query optimization detailed explanation
>>: CSS3 realizes the effect of triangle continuous enlargement
Background <br />Students who work on the fr...
1. Add in package.json "main": "el...
Note: Currently, the more popular front-end frame...
MySQL downloads for all platforms are available a...
1. Introduction By enabling the slow query log, M...
This article example shares the specific code of ...
Vue2+elementui's hover prompts are divided in...
Table of contents Preface 1. Define label style 2...
Preface In actual development, business requireme...
Let’s start the discussion from a common question...
Port mapping is not the only way to connect Docke...
HTML-centric front-end development is almost what ...
Remark: The amount of data in this article is 1 m...
Simple use of Vue bus Scenario description: Compo...
Table of contents Preparation Deployment process ...