How do i check the networking on my docker container?



  • Man page for docker run: http://bit.ly/2h77MqO
    Man page for docker exec: http://bit.ly/2j6Khm9

    The default networking when creating new containers is the bridged networking, all container communicate over that network type.

    Create a docker container to run busybox and run nc -lp on port 5001.

    $ docker run --name busybee -d --expose 5001 busybox /bin/sh -c "echo Hello World | nc -lp 5001"
    

    Check the network interface configuration. The docker run above has been given an IP address.

    $ docker exec busybee ifconfig
    eth0      Link encap:Ethernet  HWaddr 02:42:AC:14:00:06  
              inet addr:172.17.0.3  Bcast:0.0.0.0  Mask:255.255.0.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:22 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:2770 (2.7 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:1000 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    

    Verify the output from the docker run command:

    $ docker run busybox telnet 172.17.0.3 5001
    Hello World
    Connection closed by foreign host


© Lightnetics 2024