In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "how to deploy a point-to-point docker network". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to deploy a point-to-point docker network" can help you solve the problem.
View the current network environment [root@liuxin-test01 ~] # ip A1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 0000 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:ca:41:84 brd ff:ff:ff:ff:ff:ff inet 192.168.8.192/24 brd 192.168.8.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feca:4184/64 scope link valid_lft forever preferred_lft forever3: eth2: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:0c:29:ca:41:8e brd ff:ff:ff:ff:ff:ff4 : docker0: mtu 1500 qdisc noqueue state DOWN link/ether 02:42:a3:f4:2f:40 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1 rm 16 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:a3ff:fef4:2f40/64 scope link valid_lft forever preferred_lft forever create two containers without networks-- explain the rm parameters: when the Docker container exits The file system inside the default container is still retained to facilitate debugging and retain user data. However, for the foreground container, because it only runs for a short time during development and debugging, there is no need to retain its user data, so you can set the-rm option when the container is started, so that the file system inside the container can be automatically cleaned when the container exits. -- net=none has no network environment-- the default parameter of net=bridge, which sets the network of the container through the docker0. You can also use the-b parameter of the DOCKER_OPTS option to specify the default bridge-the network environment of the net=host shared host. This is not recommended-the two containers of net=container share network resources such as IP address and port number.
The following two containers are created in two terminals
[root@liuxin-test01 ~] # docker run-- rm-it-- net=none-- name='centos01' centos:7.4.1708 [root@f64cdc7ffff1 /] # [root@liuxin-test01 ~] # docker run-- rm-it-- net=none-- name='centos02' centos:7.4.1708 [root@cd4df383b68e /] # View the process ID [root@liuxin-test01 ~] # docker inspect-f'{{.State.Pid}} 'f6421682 [root@liuxin-test01 ~] of these two containers ] # docker inspect-f'{{.State.Pid}} 'cd421832 creates a virtual cyberspace for the two containers [root@liuxin-test01 ~] # mkdir-p / var/run/netns [root@liuxin-test01 ~] # ln-s / proc/21682/ns/net / var/run/netns/21682 [root@liuxin-test01 ~] # ln-s / proc/21832/ns/net / var/run/netns/21832 [root@liuxin-test01 ~] # create a pair of veth Both ends are named An and B
Veth is a virtual Ethernet device, similar to a network card device. This is the introduction of linux container technology, which requires it to appear in pairs.
[root@liuxin-test01 ~] # ip link add A type veth peer name B [root@liuxin-test01 ~] # ip A1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_ Fast state UP qlen 1000 link/ether 00:0c:29:ca:41:84 brd ff:ff:ff:ff:ff:ff inet 192.168.8.192/24 brd 192.168.8.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feca:4184/64 scope link valid_lft forever preferred_lft forever3: eth2: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:0c:29:ca:41:8e brd ff: Ff:ff:ff:ff:ff4: docker0: mtu 1500 qdisc noqueue state DOWN link/ether 02:42:a3:f4:2f:40 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1 16 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:a3ff:fef4:2f40/64 scope link valid_lft forever preferred_lft forever157: bag A: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether de:f7:3b: 24:a5:0e brd ff:ff:ff:ff:ff:ff158: aheb: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 9a:65:96:de:04:90 brd ff:ff:ff:ff:ff:ff put both ends in two containers
We can see that after adding to the container, we can no longer see these two devices when we execute ip an again.
[root@liuxin-test01 ~] # ip link set A netns 21682 [root@liuxin-test01 ~] # ip link set B netns 21832 [root@liuxin-test01 ~] # ip A1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 0000 brd 0000 inet 127.0.0.1 inet 127.0.0.1 8 scope host lo valid_lft forever preferred_lft forever inet6:: 1right 128 scope host valid_lft forever preferred _ lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:ca:41:84 brd ff:ff:ff:ff:ff:ff inet 192.168.8.192/24 brd 192.168.8.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feca:4184/64 scope link valid_lft forever preferred_lft forever3: eth2: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00: 0c:29:ca:41:8e brd ff:ff:ff:ff:ff:ff4: docker0: mtu 1500 qdisc noqueue state DOWN link/ether 02:42:a3:f4:2f:40 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:a3ff:fef4:2f40/64 scope link valid_lft forever preferred_lft forever
Set the ip of two container network spaces
[root@liuxin-test01 ~] # ip netns exec 21682 ip addr add 192.168.99.1 ip addr add 32 dev A [root@liuxin-test01 ~] # ip netns exec 21832 ip addr add 192.168.99.2 32 dev B start the network of two containers [root@liuxin-test01 ~] # ip netns exec 21682 ip link set A up [root@liuxin-test01 ~] # ip netns exec 21832 ip link set B up set the gateway [root@liuxin-test01 ~] # Ip netns exec 21682 ip route add 192.168.99.2 bytes of data.64 bytes from 32 dev A [root@liuxin-test01 ~] # ip netns exec 21832 ip route add 192.168.99.1 ip route add 32 dev B Test [root@f64cdc7ffff1 /] # ping 192.168.99.2PING 192.168.99.2 (192.168.99.2) 56 (84) bytes of data.64 bytes from 192.168.99.2: icmp_seq=1 ttl=64 time=0.095 ms [root@cd4df383b68e /] # ping 192.168.99.1PING 192.168.99.1 (192.168.99.1) 56 (84) bytes of data.64 bytes from 192.168.99.1: icmp_seq=1 ttl=64 time=0.057 ms's content on "how to deploy a point-to-point docker network" ends here Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.