Docker Network:
[root@ip-172-31-39-133 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:baff:feb1:8229 prefixlen 64 scopeid 0x20<link>
ether 02:42:ba:b1:82:29 txqueuelen 0 (Ethernet)
RX packets 3478 bytes 201970 (197.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3669 bytes 40278349 (38.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 172.31.39.133 netmask 255.255.240.0 broadcast 172.31.47.255
inet6 fe80::839:a1ff:feee:a9c4 prefixlen 64 scopeid 0x20<link>
ether 0a:39:a1:ee:a9:c4 txqueuelen 1000 (Ethernet)
RX packets 148043 bytes 144043751 (137.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 55507 bytes 63376063 (60.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 4 bytes 336 (336.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 336 (336.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth07253cd: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::9898:72ff:fe27:e131 prefixlen 64 scopeid 0x20<link>
ether 9a:98:72:27:e1:31 txqueuelen 0 (Ethernet)
RX packets 31 bytes 2696 (2.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 85 bytes 6743 (6.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth2476f03: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::b868:acff:fe2b:7dca prefixlen 64 scopeid 0x20<link>
ether ba:68:ac:2b:7d:ca txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 67 bytes 4174 (4.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth4cb9aff: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::7ce8:34ff:fea3:481c prefixlen 64 scopeid 0x20<link>
ether 7e:e8:34:a3:48:1c txqueuelen 0 (Ethernet)
RX packets 145 bytes 13579 (13.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 194 bytes 12477 (12.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth6d62ecd: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::649b:22ff:fe21:ffa4 prefixlen 64 scopeid 0x20<link>
ether 66:9b:22:21:ff:a4 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 892 (892.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vetha672711: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::bc7e:c1ff:fe05:ebbd prefixlen 64 scopeid 0x20<link>
ether be:7e:c1:05:eb:bd txqueuelen 0 (Ethernet)
RX packets 19 bytes 2577 (2.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31 bytes 2713 (2.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@ip-172-31-39-133 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c995d28b99c4 nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp thirsty_dubinsky
4f8882709160 nginx "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 80/tcp optimistic_tesla
0171ffaaa59e copydemo "nginx -g 'daemon of…" 14 hours ago Up 14 hours 0.0.0.0:3365->80/tcp, :::3365->80/tcp goofy_blackwell
b97ae09e1692 nginx "/docker-entrypoint.…" 15 hours ago Up 15 hours 0.0.0.0:3306->80/tcp, :::3306->80/tcp priceless_hermann
5d3b1c485eb1 ubuntu "bash" 24 hours ago Up 24 hours amazing_wilson
[root@ip-172-31-39-133 ~]#
Create new container without passing port number:
[root@ip-172-31-39-133 ~]# docker run -itd -P nginx
c995d28b99c47ef0289ab4c679353931140a7c1eef68d3345a27377beebe1cdb
[root@ip-172-31-39-133 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c995d28b99c4 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 0.0.0.0:49153->80/tcp, :::49153->80/tcp thirsty_dubinsky
We can see container is running it took host port 49153 automatically.
[root@ip-172-31-39-133 ~]# docker network --help
Usage: docker network COMMAND
Manage networks
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
Create new network:
[root@ip-172-31-39-133 ~]# docker network create -d bridge my_network
43f46e2b33a1e49805b4adb8b9f7304d4a4682e7182b094d975bee0110a7edf2
[root@ip-172-31-39-133 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
32e70e010db8 bridge bridge local
21f7ccbe7a2b host host local
43f46e2b33a1 my_network bridge local
a2057ad1b8e7 none null local
[root@ip-172-31-39-133 ~]#
On creating new network we can see new interface also created.
[root@ip-172-31-39-133 ~]# ifconfig
br-43f46e2b33a1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.19.0.1 netmask 255.255.0.0 broadcast 172.19.255.255
ether 02:42:67:2e:c6:dd txqueuelen 0 (Ethernet)
RX packets 19 bytes 2577 (2.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 2783 (2.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@ip-172-31-39-133 ~]# docker container run -itd --network my_network nginx
7cd1dfca58a85b928bb56c96a3fd9286f20670aaf0e326e890eacdd8b9a8a1ac
[root@ip-172-31-39-133 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7cd1dfca58a8 nginx "/docker-entrypoint.…" 5 seconds ago Up 4 seconds 80/tcp cool_saha
[root@ip-172-31-39-133 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP group default qlen 1000
link/ether 0a:39:a1:ee:a9:c4 brd ff:ff:ff:ff:ff:ff
inet 172.31.39.133/20 brd 172.31.47.255 scope global dynamic eth0
valid_lft 3285sec preferred_lft 3285sec
inet6 fe80::839:a1ff:feee:a9c4/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ba:b1:82:29 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:baff:feb1:8229/64 scope link
valid_lft forever preferred_lft forever
5: veth2476f03@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether ba:68:ac:2b:7d:ca brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::b868:acff:fe2b:7dca/64 scope link
valid_lft forever preferred_lft forever
13: veth4cb9aff@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 7e:e8:34:a3:48:1c brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::7ce8:34ff:fea3:481c/64 scope link
valid_lft forever preferred_lft forever
35: veth07253cd@if34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 9a:98:72:27:e1:31 brd ff:ff:ff:ff:ff:ff link-netnsid 2
inet6 fe80::9898:72ff:fe27:e131/64 scope link
valid_lft forever preferred_lft forever
60: veth6d62ecd@if59: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 66:9b:22:21:ff:a4 brd ff:ff:ff:ff:ff:ff link-netnsid 3
inet6 fe80::649b:22ff:fe21:ffa4/64 scope link
valid_lft forever preferred_lft forever
62: vetha672711@if61: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether be:7e:c1:05:eb:bd brd ff:ff:ff:ff:ff:ff link-netnsid 4
inet6 fe80::bc7e:c1ff:fe05:ebbd/64 scope link
valid_lft forever preferred_lft forever
63: br-43f46e2b33a1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:67:2e:c6:dd brd ff:ff:ff:ff:ff:ff
inet 172.19.0.1/16 brd 172.19.255.255 scope global br-43f46e2b33a1
valid_lft forever preferred_lft forever
inet6 fe80::42:67ff:fe2e:c6dd/64 scope link
valid_lft forever preferred_lft forever
65: veth35fc2fc@if64: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-43f46e2b33a1 state UP group default
link/ether 1e:01:18:82:83:fd brd ff:ff:ff:ff:ff:ff link-netnsid 5
inet6 fe80::1c01:18ff:fe82:83fd/64 scope link
valid_lft forever preferred_lft forever
[root@ip-172-31-39-133 ~]#
In above diagram if one bridge container wants to communicate other they should communicate vai host interface.
ex: wget ip:3333
Host Network:
[root@ip-172-31-39-133 ~]# docker container run -it --network=host nginx
You can see your container and host are same.
Container will be isolated but its use same host network.
You can access nginx service using host ip.
Null Network: Container which is not connected to any network.
[root@ip-172-31-39-133 ~]# docker container run -it --network=none ubuntu
root@fd7fb116f4c3:/#
Its isolated container.
We can see container created with loopback address.
Connect and Disconnect:
[root@ip-172-31-39-133 ~]# docker network disconnect none <container_id>
[root@ip-172-31-39-133 ~]# docker network connect my_network <container_id>
No comments:
Post a Comment