In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "how to configure docker network", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to configure docker network" this article.
Network docker network of docker
Docker has three default networks
[root@srv00 ~] # docker network lsNETWORK ID NAME DRIVERb891bd36a3f1 bridge bridge 739cb6a018f7 host host d0e062995920 none null
The default containers are all running under bridge network.
Run a container test
[root@srv00 ~] # docker run-itd-- name nw centos5ffb7062805af03b00ecc6160a78c855a7d1b7c32bfcc14d78ce036f2df9a517 [root@srv00 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES5ffb7062805a centos "/ bin/bash" About a minute ago Up About a minute nw
-- name names the container, otherwise docker names automatically.
Check out the containers under the bridge network:
[root@srv00 ~] # docker network inspect bridge [{"Name": "bridge", "Id": "b891bd36a3f12dc2bb1f4526c0fc2741c0f8ccf6011071116840b6b31f9b20ac", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": {"Driver": "default", "Options": null "Config": [{"Subnet": "172.17.0.0swap 16", "Gateway": "172.17.42.1"}]}, "Internal": false "Containers": {"5ffb7062805af03b00ecc6160a78c855a7d1b7c32bfcc14d78ce036f2df9a517": {"Name": "nw", "EndpointID": "65f410576be2d9aadb697ebb820e372ffb2073db7868ec001e87da5c8cf40d71", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2 IPv6Address 16", "IPv6Address": ""} "616d942216ee7050ecff07ca66d2d7583d4093820e9d1448f96b417d7d779408": {"Name": "high_shockley", "EndpointID": "de09ec8b400b2724238d78ece5ff24201b7baffcdb7279809ea6b1beae5fec1d", "MacAddress": "02:42:ac:11:00:06", "IPv4Address": "172.17.0.6 max 16", "IPv6Address": ""} "dead20777b6c1609ab968966b3589904d44f8a12c124c178fd5cb540052cce6f": {"Name": "gloomy_cray", "EndpointID": "1ba62447dd2d89165fc7079442a2016fb1c44caa02cca7cda6bf363eec2841da", "MacAddress": "02:42:ac:11:00:07", "IPv4Address": "172.17.0.7 IPv4Address 16", "IPv6Address": ""} "e709f66c9bdbcc20f92b804e483bb566bc4ee934fa1e2e5cdbf4759f7ac1923c": {"Name": "tiny_shockley", "EndpointID": "a070387813fc17fd54ab389b4afe40c80c5dbbe42c86983a89a84a65cf32e378", "MacAddress": "02:42:ac:11:00:01", "IPv4Address": "172.17.0.1 IPv4Address", "IPv6Address": ""}} "Options": {"com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0" "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500"}, "Labels": {}]
You can see that the ip of the container nw you just ran is 172.17.0.2
We can remove a container from the network
[root@srv00] # docker exec-it high_shockley / bin/bash [root@616d942216ee /] # ping 172.17.0.2PING 172.17.0.2 (172.17.0.2) 56 (84) bytes of data.64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.100 ms64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.065 Ms ^ C-172.17.0.2 ping statistics-2 packets transmitted, 2 received, 0 packet loss Time 999msrtt min/avg/max/mdev = 0.065 ms [root@616d942216ee /] # exitexit
First enter ping, another container on the same network, and you can ping.
[root@srv00] # docker network disconnect bridge nw [root@srv00 ~] # docker exec-it high_shockley / bin/bash [root@616d942216ee /] # ping 172.17.0.2 PING 172.17.0.2 (172.17.0.2) 56 (84) Bytes of data ^ C-172.17.0.2 ping statistics-3 packets transmitted 0 received, 100% packet loss, time 1999ms [root@616d942216ee /] # exitexit [root@srv00 ~] # docker network inspect bridge...
You can see that ping doesn't work. Also not in the bridge network. There is no ip address through docker inspect nw.
Create your own bridge network
Docker supports two network driver types: 'bridge'' and 'overlay. Bridge' is a network running on a unified host. Overlay can include multiple hosts.
Here, let's first create our own bridge' network.
[root@srv00 ~] # docker network create-d bridge mynetwork072dbe030461bc1f7e1bc4829017f13ade899b09b606d12dfb8b6dec496a08bf [root@srv00] # docker network lsNETWORK ID NAME DRIVERb891bd36a3f1 bridge bridge 739cb6a018f7 host host 072dbe030461 mynetwork bridge d0e062995920 none null [root@srv00 ~] # Docker network inspect mynetwork [{"Name": "mynetwork" Id: "072dbe030461bc1f7e1bc4829017f13ade899b09b606d12dfb8b6dec496a08bf", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": {"Driver": "default", "Options": {} "Config": [{"Subnet": "172.18.0.0 Containers 16", "Gateway": "172.18.0.1 Options 16"}]}, "Internal": false, "Containers": {}, "Options": {} "Labels": {}}]
Mynetwork, there is no next container.
Run a container under mynetwork
[root@srv00] # docker run-itd-- net mynetwork-- name nw1 centosc5b59a1e180753301460b597b87b1608b00ebe2b8620b41b8851938c6eab8044 [root@srv00 ~] # docker network inspect mynetwork [{"Name": "mynetwork", "Id": "072dbe030461bc1f7e1bc4829017f13ade899b09b606d12dfb8b6dec496a08bf", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": {"Driver": "default" "Options": {}, "Config": [{"Subnet": "172.18.0.0 Internal 16", "Gateway": "172.18.0.1 Universe 16"}]}, "Internal": false "Containers": {"c5b59a1e180753301460b597b87b1608b00ebe2b8620b41b8851938c6eab8044": {"Name": "nw1", "EndpointID": "ed444519fd958ddd83d64f62719f485f62d284f2a647536e4f48a8128e62ad5e", "MacAddress": "02:42:ac:12:00:02", "IPv4Address": "172.18.0.2 max 16" "IPv6Address": ""}}, "Options": {}, "Labels": {}}]
To test the interoperability, first connect nw to the bridge network.
[root@srv00 ~] # docker network connect bridge nw [root@srv00 ~] # docker exec-it nw / bin/bash [root@5ffb7062805a /] # ping 172.18.0.2 PING 172.18.0.2 (172.18.0.2) 56 (84) bytes of data ^ C-- 172.18.0.2 ping statistics-- 3 packets transmitted, 0 received, 100% packet loss, time 1999ms
Containers in different networks are impassable.
Add nw to mynetwork
[root@srv00 ~] # docker network connect mynetwork nw [root@srv00 ~] # docker network inspect mynetwork [root@srv00 ~] # docker network inspect bridge
You can see that there are nw in both networks
[root@srv00] # docker inspect-- format=' {{range .NetworkSettings.Networks}} {{end} 'nw172.17.0.2172.18.0.3 [root@srv00 ~] # docker exec-it nw / bin/bash [root@5ffb7062805a /] # ping 172.18.0.2-c3PING 172.18.0.2 (172.18.0.2) 56 (84) bytes of data.64 bytes from 172.18.0.2: icmp_seq=1 ttl=64 time=0 .093 ms64 bytes from 172.18.0.2: icmp_seq=2 ttl=64 time=0.057 ms64 bytes from 172.18.0.2: icmp_seq=3 ttl=64 time=0.076 ms--- 172.18.0.2 ping statistics-3 packets transmitted 3 received, 0% packet loss, time 2000msrtt min/avg/max/mdev = 0.057, 0.075, packet loss, 0.093, ms [root@5ffb7062805a /] # ping 172.17.0.6-c3PING 172.17.0.6 (172.17.0.6) 56 (84) bytes of data.64 bytes from 172.17.0.6: icmp_seq=1 ttl=64 time=0.102 ms64 bytes from 172.17.0.6: icmp_seq=2 ttl=64 time=0.080 Ms ^ C-172.17.0.6 ping statistics-2 packets transmitted 2 received, 0% packet loss, time 999msrtt min/avg/max/mdev = 0.080, 0.091, 0.102, ms
Nw this container has two ip, at the same time in two network segments, the containers in the two networks can communicate with each other.
The above is all the contents of the article "how to configure the docker Network". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.