从Docker容器中获取主机的Mac地址 [英] Get Mac-Address of Host from within Docker Container

查看:1181
本文介绍了从Docker容器中获取主机的Mac地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Docker化应用程序中,我需要具有硬件锚点并考虑使用Container的Mac地址.但是:由于Docker容器的Mac地址是可变的,并且在容器启动时动态分配,因此我无法使用此Mac地址(请参阅 Docker文档)

In my dockerized application I need to have a hardware anchor and thought about using the Container's Mac-Address. But: since the Mac-Address of a Docker container ist volatile and dynamically assigned at container startup I cannot use this Mac-Address (see Docker docs)

MAC地址是使用分配给IP地址的IP地址生成的.容器,以避免ARP冲突,使用范围为02:42:ac:11:00:00到02:42:ac:11:ff:ff

The MAC address is generated using the IP address allocated to the container to avoid ARP collisions, using a range from 02:42:ac:11:00:00 to 02:42:ac:11:ff:ff

Docker主机的Mac地址将是一个可行的解决方案.

The Mac-Address of the Docker host would be a viable solution.

如何从在此主机上运行的容器中访问(linux)主机的Mac地址?

How can I access the (linux) host's Mac-Address from within a container running on this host?

推荐答案

启动时,您可以将Mac地址作为环境变量传递给容器

You can pass the mac address to the container as an env variable when starting it

docker run -e mac=$(ip link show eth0 | awk '/ether/ {print $2}') alpine env

这篇关于从Docker容器中获取主机的Mac地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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