whenever you give network name as host then whatever you create container it will use same network as your host computer network
[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
[root@ip-172-31-40-217 ~]# docker container run -it --network=host ubuntu:14.04 bash
root@ip-172-31-40-217:/# ifconfig ------ This will give same output as your host computer
at a time host driver can attach with only one network
[root@ip-172-31-40-217 ~]# docker network create -d host test
Error response from daemon: network with name test already exists
[root@ip-172-31-40-217 ~]#
The main benefit of using host network is we do not need to do port mapping to access the any web server running in container we can access it by using the host ip directly ( in below case by using public ip ec2 server without opening any port
[root@ip-172-31-40-217 ~]# docker container run -itd --network=host nginx
111c466853a3d4118390f0a559a7cf3d0bc86302c4134265148a86bc8abed720
http://100.26.207.208/ -------we able to access it
[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
[root@ip-172-31-40-217 ~]# docker container run -it --network=host ubuntu:14.04 bash
root@ip-172-31-40-217:/# ifconfig ------ This will give same output as your host computer
at a time host driver can attach with only one network
[root@ip-172-31-40-217 ~]# docker network create -d host test
Error response from daemon: network with name test already exists
[root@ip-172-31-40-217 ~]#
The main benefit of using host network is we do not need to do port mapping to access the any web server running in container we can access it by using the host ip directly ( in below case by using public ip ec2 server without opening any port
[root@ip-172-31-40-217 ~]# docker container run -itd --network=host nginx
111c466853a3d4118390f0a559a7cf3d0bc86302c4134265148a86bc8abed720
http://100.26.207.208/ -------we able to access it
No comments:
Post a Comment