Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Mac-Address of Host from within Docker Container

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?

like image 564
WeSee Avatar asked Jan 15 '18 13:01

WeSee


1 Answers

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
like image 57
yamenk Avatar answered Nov 15 '22 05:11

yamenk