从Docker容器内部访问主机详细信息
问题描述:
我想知道从Docker容器中获取主机详细信息(尤其是MAC地址)的方法.
I would like to know the way to get host machine details especially the MAC address from inside 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.