且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何访问Docker容器内的主机详细信息

更新时间:2023-12-04 09:33:52

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

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.