Docker-Docker network communication mechanism & the use of bridge

Insert picture description here
Insert picture description here
Because it is on the same network segment of the same bridge, you can enter a container to access another container

curl http://172.17.0.2:8080/

But all containers use the same bridge, which will affect the bandwidth of other containers

Network configuration between containers in docker
1. Why provide network functions
docker allows network services to be provided through external access to containers or container interconnection
2. Docker container and operating system communication mechanism
3. docker network usage
note: half of them are using docker bridge (Bridge) When implementing container-to-container communication, container communication is performed from an application perspective.
a.View the docker bridge configuration:

docker network ls

Insert picture description here
b. Create a custom bridge

docker network create 网桥名称(比如:ems)

Full wording: bridge configuration (default, not adding is also the configuration of creating bridge)

docker network create -d bridge 网桥名称(ems)

Running on the default bridge, containers that are not in the same bridge cannot communicate, here they are running on a custom bridge (ems)

docker run -d -p 8080:8081 --network 网桥名称(ems) --name mytomcat tomcat:8.0

Go inside the container to view the container details

docker inspect 容器ID

Insert picture description here
Once the container is running, it will automatically map the assigned ip to the container name, even if your ip changes, but your container name does not change, the container name represents the ip address

curl http://172.18.0.2:8080
也可以这样写:curl http://mytomcat:8080

c. Delete the bridge

docker network rm 网桥名称

View the list of bridges

docker network ls

d. View bridge details

docker inspect 网桥名称

Note: It must be created first when using the bridge, but this is very troublesome, which requires the following container orchestration tool: compose

Guess you like

Origin blog.csdn.net/dgssd/article/details/114975715