Thursday, 18 July 2019

Docker Command Part-17 By Raj Gupta

How to create own network in docker container

[root@ip-172-31-40-217 ~]# docker network create -d bridge test
5e62d8b1f783f6b0f6cad70f5b74bc992010c56bed543073b17ca56051f219eb
[root@ip-172-31-40-217 ~]# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
39450de642d6        bridge              bridge              local
f6345e9bd840        host                host                local
514a936c83c1        none                null                local
5e62d8b1f783        test                bridge              local
[root@ip-172-31-40-217 ~]#
[root@ip-172-31-40-217 ~]# ifconfig
br-5e62d8b1f783 Link encap:Ethernet  HWaddr 02:42:70:A0:F7:87
          inet addr:172.18.0.1  Bcast:172.18.255.255  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  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:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Now attach docker to our own created network

[root@ip-172-31-40-217 ~]# docker container run -it --network test ubuntu:14.04 bash
root@75b823d59160:/#
root@75b823d59160:/# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:12:00:02
          inet addr:172.18.0.2  Bcast:172.18.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17 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:1326 (1.3 KB)  TX bytes:0 (0.0 B)


above connected with below virtual network on system..Once container deleted below entry also deleted

[root@ip-172-31-40-217 ~]# ifconfig
veth8193796 Link encap:Ethernet  HWaddr B2:01:04:AC:7F:D4
          inet6 addr: fe80::b001:4ff:feac:7fd4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1064 (1.0 KiB)  TX bytes:2280 (2.2 KiB)

No comments:

Post a Comment