-
[Docker] Connecting two containers via OVSCloud/Openstack_K8s_Docker 2021. 2. 24. 16:39
<Purpose>
To connect two containers via OVS.
<Topology>
<Step>
1. Creating a container.
terry@ubuntu:~$ sudo docker run -t -i --name container1 alpine
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
ba3557a56b15: Pull complete
Digest: sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Status: Downloaded newer image for alpine:latest
/ # // now we are in a container. let's check. interface will be different
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1296 (1.2 KiB) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ #2. Creating second container in new putty window
terry@ubuntu:~$ sudo docker ps // we can see container1 running on ubuntu
[sudo] password for terry:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4a5e28dbd82d alpine "/bin/sh" 3 minutes ago Up 3 minutes container1
terry@ubuntu:~$
terry@ubuntu:~$ sudo docker run -t -i -d --name container2 alpine
9472a0ed0e7cd8bfd76e58f5acd9f692df06230027945d86ec8290501309ece6
terry@ubuntu:~$
terry@ubuntu:~$ sudo docker ps // we can see container2 starting on ubuntu
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9472a0ed0e7c alpine "/bin/sh" 12 seconds ago Up 11 seconds container2
4a5e28dbd82d alpine "/bin/sh" 6 minutes ago Up 6 minutes container1
terry@ubuntu:~$3. Creating OVS
terry@ubuntu:~$ sudo ovs-vsctl add-br ovs1
terry@ubuntu:~$ sudo ovs-vsctl show
d6db2e9b-397a-40f3-b842-bb66874d6f7e
Bridge "ovs1"
Port "ovs1"
Interface "ovs1"
type: internal
ovs_version: "2.5.9"
terry@ubuntu:~$4. Connecting Container1 to OVS
terry@ubuntu:~$ sudo ovs-docker add-port ovs1 eth1 container1 --ipaddress=173.16.1.2/24
terry@ubuntu:~$
terry@ubuntu:~$ sudo docker exec container1 ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1296 (1.2 KiB) TX bytes:0 (0.0 B)
eth1 Link encap:Ethernet HWaddr DA:AA:5A:6E:3A:02
inet addr:173.16.1.2 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
terry@ubuntu:~$5. Connecting Container2 to OVS
terry@ubuntu:~$ sudo ovs-docker add-port ovs1 eth1 container2 --ipaddress=173.16.1.3/24
terry@ubuntu:~$
terry@ubuntu:~$ sudo docker exec container2 ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:03
inet addr:172.17.0.3 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
eth1 Link encap:Ethernet HWaddr EE:B9:4E:5C:85:45
inet addr:173.16.1.3 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
terry@ubuntu:~$6. Checking the interface connection on OVS
terry@ubuntu:~$ sudo ovs-vsctl show
d6db2e9b-397a-40f3-b842-bb66874d6f7e
Bridge "ovs1"
Port "3dde9c9d3dd84_l" // Container1
Interface "3dde9c9d3dd84_l"
Port "ovs1"
Interface "ovs1"
type: internal
Port "d2aed7715ae94_l" // Container2
Interface "d2aed7715ae94_l"
ovs_version: "2.5.9"
terry@ubuntu:~$7. Let's go back to container1 window
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1296 (1.2 KiB) TX bytes:0 (0.0 B)
eth1 Link encap:Ethernet HWaddr DA:AA:5A:6E:3A:02
inet addr:173.16.1.2 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ #8. Ping to container2 from container1
/ # ping 173.16.1.3
PING 173.16.1.3 (173.16.1.3): 56 data bytes
64 bytes from 173.16.1.3: seq=0 ttl=64 time=1.032 ms
64 bytes from 173.16.1.3: seq=1 ttl=64 time=0.065 ms
64 bytes from 173.16.1.3: seq=2 ttl=64 time=0.052 ms
64 bytes from 173.16.1.3: seq=3 ttl=64 time=0.050 ms
^C
--- 173.16.1.3 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.050/0.299/1.032 ms
/ #terry@ubuntu:~$ sudo docker exec container2 ping 173.16.1.2
PING 173.16.1.2 (173.16.1.2): 56 data bytes
64 bytes from 173.16.1.2: seq=0 ttl=64 time=0.112 ms
64 bytes from 173.16.1.2: seq=1 ttl=64 time=0.086 ms
64 bytes from 173.16.1.2: seq=2 ttl=64 time=0.072 ms
64 bytes from 173.16.1.2: seq=3 ttl=64 time=0.087 ms
^C
terry@ubuntu:~$'Cloud > Openstack_K8s_Docker' 카테고리의 다른 글
[ONOS] Connecting ONOS to OvS (0) 2021.02.24 [ONOS] Installation on Ubuntu16 (0) 2021.02.24 [Docker] installation on Ubuntu 16.04.7 LTS (0) 2021.02.24 OVS(Open Virtual Switch) installation on Ubuntu 16.04.7LTS (0) 2021.02.24 Openstack Train "No valid host was found." troubleshooting (0) 2020.07.27