I read a lot of information on the Internet related to "Communication between docker containers_How to achieve communication between containers in docker", and finally decided to use docker to create a new network (-d bridge network driver is bridge), connect both containers to the network, and achieve data interaction. Here’s how: Create a network yourself [root@docker ~]# docker network create -d bridge my-bridge 01f3d92281d7dd6eaeabd77c95c62f0d33f8d45bd0e1bc7c7e1c3208526dfd2a
View the created network: Start a container and use the self-built network my-bridge [root@docker ~]# docker run -d --name test3 --network my-bridge cgy/mycentos:v2 /bin/bash -c "while true;do sleep 3600;done" 44d549f38e2a38d528d26193c5585f8c68008411d764ad39d23dc57ee48ab28c
The container started using a self-built network, the IP is 172.18.0.2 Start another container test4, do not use –network to specify the network, and use the docker0 network by default: [root@docker ~]# docker run -d --name test4 cgy/mycentos:v2 /bin/bash -c "while true;do sleep 3600;done" c64c2993e94a3dc0359a0e38ed5f5d262c0b01be45bacdf1788c7b0c2223777b When containers test3 and test4 are not associated, pinging is unsuccessful regardless of whether the container name or the container IP is used: Add test4 to the self-built my-bridge [root@docker ~]# docker network connect my-bridge test4
Check test4 and you will see that there is one more virtual network card, and it is in the same network segment as test3. At this time, you can directly use the container name to communicate Check the detailed information of my-bridge again [root@docker ~]# docker network inspect my-bridge [ { "Name": "my-bridge", "Id": "01f3d92281d7dd6eaeabd77c95c62f0d33f8d45bd0e1bc7c7e1c3208526dfd2a", "Created": "2018-05-01T01:08:04.864178764+08:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": {}, "Config": [ { "Subnet": "172.18.0.0/16", "Gateway": "172.18.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "44d549f38e2a38d528d26193c5585f8c68008411d764ad39d23dc57ee48ab28c": { "Name": "test3", "EndpointID": "95f13c730e08f7c82e5f3ec555f3c3afa79a50eceb7a1f540463ba181c81d05c", "MacAddress": "02:42:ac:12:00:02", "IPv4Address": "172.18.0.2/16", "IPv6Address": "" }, "c64c2993e94a3dc0359a0e38ed5f5d262c0b01be45bacdf1788c7b0c2223777b": { "Name": "test4", "EndpointID": "9b41a9ef9b3e6dabdaad52167642a74aa7e05f93ceec65768b311945c8f2c036", "MacAddress": "02:42:ac:12:00:03", "IPv4Address": "172.18.0.3/16", "IPv6Address": "" } }, "Options": {}, "Labels": {} } ]
Reference: https://www.jianshu.com/p/a9dce5179e31 This is the end of this article about how to implement communication between Docker containers. For more information about Docker container communication, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Details on using bimface in vue
This article lists some tips and codes about form...
This case is based on CentOS 7 system Suitable fo...
1. COUNT(*) and COUNT(COL) COUNT(*) usually perfo...
The latest Perfect Aloe Vera Gel packaging box ha...
Preface When using Docker in a production environ...
VirtualBox is a free and open source virtualizati...
This article describes the steps to install the p...
Table of contents MySQL's current_timestamp p...
Shtml and asp are similar. In files named shtml, s...
01. Infinity Font Download 02. Banda Font Download...
Mini Program Data Cache Related Knowledge Data ca...
MySQL sequence AUTO_INCREMENT detailed explanatio...
Compared with Windows system, Linux system provid...
Mobile Mobile pages only need to be compatible wi...
1. Command Introduction The passwd command is use...