Get Mac-Address of Host from within Docker Container

时光怂恿深爱的人放手 提交于 2021-01-26 17:48:47

问题


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)

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

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

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


回答1:


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



回答2:


If you run in net mode "host" you can retrive the mac from the container, and wouldn't need to pass it in.



来源:https://stackoverflow.com/questions/48264224/get-mac-address-of-host-from-within-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!