从该服务器内运行的Docker容器中找到服务器的IP地址
我有一台服务器,在此服务器内部,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以安装IPROUTE2软件包,并使用
ip
命令显示这样的默认路由以获取IP地址,您可以
将其纳入脚本中的变量,请执行
You can install the iproute2 package and use the
ip
command to show the default route like thisTo just get the IP address, you can do
To get it into a variable in a script, do