从该服务器内运行的Docker容器中找到服务器的IP地址

发布于 2025-01-23 19:18:33 字数 133 浏览 1 评论 0原文

我有一台服务器,在此服务器内部,Docker容器正在运行,在容器内有一个Shell脚本,该脚本需要服务器的IP,而不是Docker容器的IP。有什么方法可以得到吗?

我很长一段时间以来谷歌搜索,但找不到类似的问题。

请帮忙。

I have a server and inside this server a docker container is running, I have a shell script inside the container which needs the ip of the server not the ip of the docker container. Is there any way to get that ?

I googled for long time and I wasn't able to find a similar question.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2025-01-30 19:18:33

您可以安装IPROUTE2软件包,并使用ip命令显示这样的默认路由

ip route show default

以获取IP地址,您可以

ip route show default | awk '{print $3}'

将其纳入脚本中的变量,请执行

HOSTIP=$(ip route show default | awk '{print $3}')

You can install the iproute2 package and use the ip command to show the default route like this

ip route show default

To just get the IP address, you can do

ip route show default | awk '{print $3}'

To get it into a variable in a script, do

HOSTIP=$(ip route show default | awk '{print $3}')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文