Published 6月 01, 2019 by with 0 comment

4 - 04 - Docker DNS and Joined



In this lab, I will study two labs, Docker DNS and joined container.
If we create container with --name, we can use container name to ping each other.
Joined container, If create a container 1 with --network=conatiner:container2.
The container 1 network configuration will same as container2

1. Docker DNS.
1a. In 4 - 03 - Adding a NIC, we had created Busybox1, let's Starting the container(Busybox1).
peter@peter-KVM:~$ docker start Busybox1
Busybox1
peter@peter-KVM:~$ 
peter@peter-KVM:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
715d7783bce9        busybox             "sleep 3000"        19 hours ago        Up 8 seconds                            Busybox1
peter@peter-KVM:~$ 
peter@peter-KVM:~$ brctl show
bridge name     bridge id               STP enabled     interfaces
br-11e6e8ed82ce         8000.0242a401537a       no              veth0db2634
br-4e4d06e66f42         8000.02420c6f213f       no
docker0         8000.024219252d6f       no
peter@peter-KVM:~$ 

1b. In 4 - 03 - Adding a NIC, we had created Busybox2, let's Starting the container(Busybox2).
peter@peter-KVM:~$ docker start Busybox2
Busybox2
peter@peter-KVM:~$ 
peter@peter-KVM:~$ brctl show
bridge name     bridge id               STP enabled     interfaces
br-11e6e8ed82ce         8000.0242a401537a       no              veth0db2634
                                                        vethd5e2bba
br-4e4d06e66f42         8000.02420c6f213f       no
docker0         8000.024219252d6f       no
peter@peter-KVM:~$ 

1c. Into Busybox1 and use DNS name to ping Busybox2
peter@peter-KVM:~$ docker exec -it Busybox1 sh
/ #  
/ # ping -c 3 Busybox2
PING Busybox2 (192.168.1.20): 56 data bytes
64 bytes from 192.168.1.20: seq=0 ttl=64 time=0.100 ms
64 bytes from 192.168.1.20: seq=1 ttl=64 time=0.126 ms
64 bytes from 192.168.1.20: seq=2 ttl=64 time=0.455 ms

--- Busybox2 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.100/0.227/0.455 ms
/ # 
/ # exit
peter@peter-KVM:~$ 


2. Joined Container.
2a. In 4 - 03 - Adding a NIC, we had created Busybox3, let's Starting the container(Busybox3).
peter@peter-KVM:~$ docker start Busybox3 
Busybox3
peter@peter-KVM:~$ 

2b. In to Busybox3 and check its NIC info.
peter@peter-KVM:~$ docker exec -it Busybox3 sh
/ # ip a
1: lo:  mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
142: eth1@if143:  mtu 1500 qdisc noqueue 
    link/ether 02:42:c0:a8:02:1e brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.30/24 brd 192.168.2.255 scope global eth1
       valid_lft forever preferred_lft forever
144: eth0@if145:  mtu 1500 qdisc noqueue 
    link/ether 02:42:c0:a8:01:1e brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.30/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # 
/ # exit
peter@peter-KVM:~$ 
2c. Now we will create a joined container call NMS.
peter@peter-KVM:~$ docker run -itd --name NMS --network=container:Busybox3 busybox sleep 3000
b1605d42fddfcf329ac1db12b19fa0b574f156f238698d8ce64d127549cec2ed
peter@peter-KVM:~$ 
2d. Into the NMS container, you will see the NIC is same as Busybox3. NMS and Busybox3 share same network.
peter@peter-KVM:~$ docker exec -it NMS sh
/ # 
/ # ip a
1: lo:  mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
142: eth1@if143:  mtu 1500 qdisc noqueue 
    link/ether 02:42:c0:a8:02:1e brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.30/24 brd 192.168.2.255 scope global eth1
       valid_lft forever preferred_lft forever
144: eth0@if145:  mtu 1500 qdisc noqueue 
    link/ether 02:42:c0:a8:01:1e brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.30/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # 
/ # ping -c 3 Busybox3
PING Busybox3 (192.168.1.30): 56 data bytes
64 bytes from 192.168.1.30: seq=0 ttl=64 time=0.050 ms
64 bytes from 192.168.1.30: seq=1 ttl=64 time=0.103 ms
64 bytes from 192.168.1.30: seq=2 ttl=64 time=0.089 ms

--- Busybox3 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.050/0.080/0.103 ms
/ # 




Reference:
1. 4 - 03 - Adding a NIC
http://juilin77.blogspot.com/2019/05/4-03-adding-nic.html


最初發表 / 最後更新: 2019.06.01 / 2019.06.01

0 comments:

張貼留言