Docker 如何为容器分配 MAC 地址? [英] How does the Docker assign MAC addresses to containers?

查看:87
本文介绍了Docker 如何为容器分配 MAC 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我启动新容器时,Docker 会自动为它们分配一些 MAC 地址.我很好奇这个任务是否有规律.MAC地址可以改吗?

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?

$ docker network inspect bridge

$ docker network inspect bridge

"Containers": {
            "3386a527aa08b37ea9232cbcace2d2458d49f44bb05a6b775fba7ddd40d8f92c": {
                "EndpointID": "647c12443e91faf0fd508b6edfe59c30b642abb60dfab890b4bdccee38750bc1",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            },
            "94447ca479852d29aeddca75c28f7104df3c3196d7b6d83061879e339946805c": {
                "EndpointID": "b047d090f446ac49747d3c37d63e4307be745876db7f0ceef7b311cbba615f48",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            }

推荐答案

Docker 开始为第一个容器分配总是相同的 mac 02:42:ac:11:00:02 然后增加对于每个不同的容器,每个 mac 对应一个.

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.

不确定他们为什么使用那个 mac 地址.似乎 02:42:ac 与 oui 数据库中的任何真实供应商都不匹配.查看关于此的官方文档.他们说:

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:

使用分配给容器的 IP 地址生成 MAC 地址以避免 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 run 命令上的 --mac-address 参数在容器生成时设置任何 mac 地址.例如执行这样的命令 docker run -ti --mac-address 00:00:00:00:00:11 ubuntu:trusty

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

希望对你有帮助.

这篇关于Docker 如何为容器分配 MAC 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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