Docker Network


## create the first container
## check the ip address
## and start a web server

%ip addr show dev docker0
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:5a:e8:08:4a brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:5aff:fee8:84a/64 scope link 
       valid_lft forever preferred_lft forever
%sudo docker run --rm -it busybox
/ # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> 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
33: eth0@if34: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # cd var/www/
/var/www # ls
/var/www # echo hello, world >index.txt
/var/www # httpd
/var/www # ps
PID   USER     TIME   COMMAND
    1 root       0:00 sh
   11 root       0:00 httpd
   12 root       0:00 ps
/var/www # cd
~ # pwd
/root
/ #   (^P^Q)
%sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS              PORTS     NAMES
3ded353cc8c3   busybox   "sh"      2 minutes ago   Up About a minute             mystifying_hoover

## create the second container
## and ping to first container

%sudo docker run --rm -it busybox
/ # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> 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
35: eth0@if36: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # ping -c1 172.17.0.2
PING 172.17.0.2 (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.592 ms

--- 172.17.0.2 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.592/0.592/0.592 ms
/ #   (^P^Q)
%sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED              STATUS              PORTS     NAMES
418f391f62c2   busybox   "sh"      About a minute ago   Up About a minute             thirsty_euler
3ded353cc8c3   busybox   "sh"      3 minutes ago        Up 3 minutes                  mystifying_hoover

## attach second container again
## and retrieve web page from the web server on the first container

%sudo docker attach 418
/ # telnet 172.17.0.2 80
GET /index.txt

HTTP/1.0 200 OK
Content-type: text/plain
Date: Wed, 08 Jun 2022 10:08:49 GMT
Connection: close
Accept-Ranges: bytes
Last-Modified: Wed, 08 Jun 2022 10:06:37 GMT
Content-length: 13

hello, world
Connection closed by foreign host
/ # printf 'GET /index.txt\n\n' | nc 172.17.0.2 80
HTTP/1.0 200 OK
Content-type: text/plain
Date: Wed, 08 Jun 2022 10:38:39 GMT
Connection: close
Accept-Ranges: bytes
Last-Modified: Wed, 08 Jun 2022 10:06:37 GMT
Content-length: 13

hello, world
/ # wget -qO- http://172.17.0.2/index.txt
hello, world
/ #   (^P^Q)
%printf 'GET /index.txt\n\n' | nc 172.17.0.2 80
HTTP/1.0 200 OK
Content-type: text/plain
Date: Wed, 08 Jun 2022 13:15:47 GMT
Connection: close
Accept-Ranges: bytes
Last-Modified: Wed, 08 Jun 2022 10:06:37 GMT
Content-length: 13

hello, world
%