如何访问Docker容器内的主机详细信息 [英] How to access host machine details inside the docker container

查看:94
本文介绍了如何访问Docker容器内的主机详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用docker容器运行我们的应用程序之一(需要将主机系统信息发送到云),我想知道从Docker容器内部获取主机详细信息(尤其是MAC地址)的方法.

Using docker container to run one of our applications, required to send the host system information to the cloud, I would like to know the way to get host machine details especially the MAC address from inside the Docker container.

推荐答案

也许您可以采用不同的方法来解决此问题.例如.通过环境变量将所需的信息从主机传递到容器.

Maybe you can approach this problem different way. Eg. pass information you need from host to container via environment variables.

docker run -e HOST_MAC=$(ifconfig -a | grep -Po 'HWaddr \K.*$') image

这需要您更改容器的运行方式,但这可能是解决此问题的最干净的方法.

This requires you to change how you run a container, however it's probably the cleanest method of solving this.

这篇关于如何访问Docker容器内的主机详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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