How does the Docker assign MAC addresses to containers?

后端 未结 1 1585
逝去的感伤
逝去的感伤 2021-01-31 14:53

When I start new containers, Docker automatically assigns some MAC address to them. I am curious if there is a pattern to this assignment. Can the MAC address be changed?

<
相关标签:
1条回答
  • 2021-01-31 15:36

    Docker start assigning always the same mac 02:42:ac:11:00:02 for the first container and then is increasing by one each mac for each different container.

    Not sure why they are using that mac address. It seems 02:42:ac doesn't match any real vendor in oui databases. Look at the official documentation about this. They say:

    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

    Anyway, you can set any mac address on container generation using --mac-address parameter on the docker run command. For example doing a command like this docker run -ti --mac-address 00:00:00:00:00:11 ubuntu:trusty

    Hope it helps.

    0 讨论(0)
提交回复
热议问题