Thursday, July 21, 2016

Docker Network Demo - Part 1


Install
On Linux distributions
Installation on Ubuntu

Make sure you reboot

While I don't know about running docker in windows, you can use VirtualBox to create an experimentation OS on your host.


nelson@lab1 - is the host Ubuntu System running LTS 14.04

I open two terminals into the host to experiment with it.  I'm using putty.

Once docker is running as a service

docker pull alpine   (this gets you a local os image to work with)

nelson@lab1:~$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
e110a4a17941: Already exists
Digest: sha256:3dcdb92d7432d56604d4545cbd324b14e647b313626d99b889d0626de158f73a
Status: Downloaded newer image for alpine:latest

docker images (show's you what's in the image repo)

nelson@lab1:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              c54a2cc56cbb        2 weeks ago         1.848 kB
alpine              latest              4e38e38c8ce0        4 weeks ago         4.799 MB

docker run -it alpine /bin/sh (runs the shell from alpine)

nelson@lab1:~$ docker run -it alpine /bin/sh
/ #

WHOOT!  You have a shell!

nelson@lab1:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    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
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether fc:aa:14:98:ca:29 brd ff:ff:ff:ff:ff:ff
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether fc:aa:14:98:ca:2b brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d8:fc:93:47:01:fd brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.24/24 brd 192.168.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::dafc:93ff:fe47:1fd/64 scope link
       valid_lft forever preferred_lft forever
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:5e:2d:df:17 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:5eff:fe2d:df17/64 scope link
       valid_lft forever preferred_lft forever
17: vethc07b410: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether b6:c1:69:71:74:31 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::b4c1:69ff:fe71:7431/64 scope link
       valid_lft forever preferred_lft forever

     IP Addressing!  look at docker0 (zero), yes, it's wasting space, but we can change that later

nelson@lab1:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
d148901e8f70        alpine              "/bin/sh"           About a minute ago   Up About a minute                       stoic_curie

Ping something that should be reachable from your network.  I chose the universal loopback.  (Just kidding, don't use 8.8.8.8 as a loopback.)

/ # ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=57 time=24.921 ms
64 bytes from 8.8.8.8: seq=1 ttl=57 time=32.615 ms
64 bytes from 8.8.8.8: seq=2 ttl=57 time=23.340 ms
64 bytes from 8.8.8.8: seq=3 ttl=57 time=22.864 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss

round-trip min/avg/max = 22.864/25.935/32.615 ms

Update:  If you want to see a little deeper into what is happening,do an ifconfig and identify the physical network port name.  Then do a tcpdump on it for icmp.  Command looks like this from the host:

sudo tcpdump -i ens33 icmp 

/ # ifconfig -a
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:02
          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:2%32519/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:138 errors:0 dropped:0 overruns:0 frame:0
          TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:16510 (16.1 KiB)  TX bytes:6657 (6.5 KiB)

Here's basically what it looks like

No comments:

Post a Comment