How to set the MAC address for Docker LXC containers?

Victor Lyuboslavsky picture Victor Lyuboslavsky · Aug 28, 2013 · Viewed 13.1k times · Source

Whenever I run a docker container, I see that it uses a random MAC address:

eth0      Link encap:Ethernet  HWaddr de:6f:de:74:bd:d9

How do I set a specific MAC address for a container run?

Will I be able to have multiple containers running simultaneously with the same MAC address? These containers do not need to access the outside network and do not need to talk to each other.

Answer

Kevin Smyth picture Kevin Smyth · Jul 31, 2015

Newer versions of docker take a --mac-address=12:34:56:78:9a:bc switch to docker run.

root@kevin-VirtualBox:~# sudo docker run --rm --mac-address"=12:34:de:b0:6b:61" ubuntu ifconfig | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 12:34:de:b0:6b:61  

See https://docs.docker.com/reference/run/