如何从Docker容器中获取Docker主机的IP地址 [英] How to get the IP address of the docker host from inside a docker container
本文介绍了如何从Docker容器中获取Docker主机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
/ sbin / ip route | awk'/ default / {print $ 3}
由于@MichaelNeale注意到,在 Dockerfile中使用此方法是没有意义的
(除非我们在构建期间需要此IP),因为此IP将在构建期间被硬编码。
As the title says. I need to be able to retrieve the IP address the docker hosts and the portmaps from the host to the container, and doing that inside of the container.
解决方案
/sbin/ip route|awk '/default/ { print $3 }'
As @MichaelNeale noticed, there is no sense to use this method in Dockerfile
(except when we need this IP during build time only), because this IP will be hardcoded during build time.
这篇关于如何从Docker容器中获取Docker主机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文