Welcome to Day 11 of 21 Days of Docker. So far I discussed the bridge driver and user-defined bridge driver.
As I mentioned earlier
- Docker networking subsystem is pluggable with the help of drivers and there are several drivers available by default which provides core networking functionality
* bridge(default)
* host
* overlay
* none
* Network Plugins
The Host Network Driver
The Host Network Driver allows containers to use the host’s network stack directly. It removes the network isolation between the docker host and the docker containers to use the hosts networking directly.
Limitation
- No two containers can use the same port(s).
Use Cases
- Simple and easy setup, one or only a few containers on a single host.
$ docker container run -dt --name mynewhost1 --network host ubuntu bash efb9e8f5615ad0a7929ca47edece524ac9780dfdda08f5656136d31446aaa009
- Let’s login to the container and run the below command
$ docker exec -it efb9e8f5615a bash # Update and install few packages # apt-get update && apt-get install net-tools && apt-get install nginx # Start the nginx daemon # /etc/init.d/nginx start * Starting nginx nginx
- If you run the ifconfig command, you will see all the interface that is exposed to host is now exposed to container
# ifconfig br-fbc7613a2354: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::42:5cff:fe4a:922b prefixlen 64 scopeid 0x20<link> ether 02:42:5c:4a:92:2b txqueuelen 0 (Ethernet) RX packets 1 bytes 28 (28.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 13 bytes 1816 (1.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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:bfff:fe91:bda1 prefixlen 64 scopeid 0x20<link> ether 02:42:bf:91:bd:a1 txqueuelen 0 (Ethernet) RX packets 11454 bytes 616831 (616.8 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 15269 bytes 50064563 (50.0 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001 inet 172.31.102.118 netmask 255.255.240.0 broadcast 172.31.111.255 inet6 2600:1f18:502:2f01:8059:3ad8:b2d0:8938 prefixlen 128 scopeid 0x0<global> inet6 fe80::816:6fff:feeb:343e prefixlen 64 scopeid 0x20<link> ether 0a:16:6f:eb:34:3e txqueuelen 1000 (Ethernet) RX packets 109967 bytes 143890223 (143.8 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 49470 bytes 5648183 (5.6 MB) 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 38 bytes 3424 (3.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 38 bytes 3424 (3.4 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 veth6182832: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::b49f:95ff:fea2:aa11 prefixlen 64 scopeid 0x20<link> ether b6:9f:95:a2:aa:11 txqueuelen 0 (Ethernet) RX packets 4 bytes 280 (280.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9 bytes 726 (726.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- Go back to the host(not container)and try to access Nginx
$ curl localhost:80 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
Pages: 1 2