Thursday, 18 July 2019

Docker Command Part-18 By Raj Gupta

How to ping a container by using container id


[root@ip-172-31-40-217 ~]# docker network create test2
70b88d7ee77d84967516ec50b184eebc54695076a93ca706ea17e8f2079959e0
[root@ip-172-31-40-217 ~]# docker container run -it --network=test2 ubuntu:14.04 bash
root@18ae8aa73cbf:/# hostname
18ae8aa73cbf
root@18ae8aa73cbf:/# [root@ip-172-31-40-217 ~]#
[root@ip-172-31-40-217 ~]# docker container run -it --network=test2 ubuntu:14.04 bash
root@daf01887e65e:/# ping 18ae8aa73cbf
PING 18ae8aa73cbf (172.19.0.2) 56(84) bytes of data.
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=1 ttl=255 time=0.070 ms
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=2 ttl=255 time=0.047 ms
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=3 ttl=255 time=0.052 ms
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=4 ttl=255 time=0.056 ms
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=5 ttl=255 time=0.053 ms
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=6 ttl=255 time=0.050 ms
64 bytes from 18ae8aa73cbf.test2 (172.19.0.2): icmp_seq=7 ttl=255 time=0.052 ms
^C
--- 18ae8aa73cbf ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6151ms
rtt min/avg/max/mdev = 0.047/0.054/0.070/0.008 ms
root@daf01887e65e:/#


So its pinging by using host name....It means DNS is enable by default in custom network(network created by us but not in default network) ....We can also ping by using container ID, container name, 


If you want by default DNS is enable whenever you create container without giving any network name then first we need to delete default network(bridge) then create your custom network with same name(bridge) ..then what ever container will create it will attach with your custom network(bridge) by default.. 

No comments:

Post a Comment