如何从 docker 容器内部获取 docker 主机的 IP 地址 [英] How to get the IP address of the docker host from inside a docker container

查看:168
本文介绍了如何从 docker 容器内部获取 docker 主机的 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说.我需要能够检索 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆