Docker

--net, HWaddr, --net-alias, grep, -c, round-robbin, dig

Naranjito 2021. 2. 22. 21:40
  • docker run -i -t -d  --name network_container_2 --net container:network_container_1 ubuntu:14.04

Let's share container network from other container(network_container_2). First, create one container(network_container_1).

HWaddr and inet addr and so one are same each other.

docker run -i -t -d  --name network_container_2 --net container:network_container_1 ubuntu:14.04
61a0b897e3762550ed20bae852a5b78d06fead6e7813bce2633a33f507136f0e

docker exec network_container_1 ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02//here  
          inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0
          
...

docker exec network_container_2 ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02//here  
          inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0

--net : Network, share the container network

container:other container ID

hey, other container ID, I am going to share my network environment with you.

 

HWaddr : Hardware Address of the ethernet interface. 

 

  • docker run -i -t -d --name network_alias_container1 --net mybridge --net-alias joohyun ubuntu:14.04

Let's create container(1,2,3) using with mybridge network what I made before(2021/02/22 - [Docker] - network, bridge, host, none).

 

--net-alias : Network-Alias, it is accessible to multi container under one network(mybridge)

 

  • docker inspect network_alias_container1 \ grep IPAdress

And then check each container's IP.

docker inspect network_alias_container1 \ grep IPAdress

...

"SecondaryIPAddresses": null,

...

"IPAddress": "",

...

"IPAddress": "172.18.0.3",

...

grep : It is the way to find a specific string in the logs of a docker container

 

  • ping -c 1 joohyun

Let's request ping by hostname joohyun after create new container which is going to access to three containers. 

docker run -i -t --name network_alias_ping --net mybridge ubuntu:14.04

root@ef0bd9a7b3c9:/# ping -c 1 joohyun
PING joohyun (172.18.0.5) 56(84) bytes of data. //here
64 bytes from network_alias_container3.mybridge (172.18.0.5): icmp_seq=1 ttl=64 time=0.272 ms

...

root@ef0bd9a7b3c9:/# ping -c 1 joohyun
PING joohyun (172.18.0.4) 56(84) bytes of data. //here is different IP
64 bytes from network_alias_container2.mybridge (172.18.0.4): icmp_seq=1 ttl=64 time=0.105 ms

...

-c : Count, stop after sending count ECHO_REQUEST packets. Pind waits for count ECHO_REQUEST packets, until the timeout  expires

 

- mybridge which I made as a bridge network, and 3 joohyun containers belong to mybridge.

- mybridge has embedded DNS which is 127.0.0.11

- when I create mybridge, I put in joohyun using with --net-alias

- IP of 3containers enrolled to DNS server as hostname joohyun

- so, if I approach hostname joohyun from any of mybridge containers, DNS server returns container's IP using with round-robin(Docker Engine implements an embedded DNS  server for containers in user-defined networks. In particular, containers that are run with a network alias(--net-alias) are resolved by this embedded DNS with the IP address of the container when the alias is used)

 

1. Request ping from hostname joohyun

2. Embedded DNS converts the hostname(joohyun) to container using with --net-alias

3. Embedded DNS returns IP

4. Returned IP showed

 

  • root@ef0bd9a7b3c9:/# dig joohyun

Let's make an interrogation to DNS using with dig. And let's see convertible IP list orders.

root@ef0bd9a7b3c9:/# dig joohyun

...

joohyun.		600	IN	A	172.18.0.5
joohyun.		600	IN	A	172.18.0.4
joohyun.		600	IN	A	172.18.0.3

...