如何设置Docker LXC容器的MAC地址? [英] How to set the MAC address for Docker LXC containers?

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

问题描述

每当我运行docker容器时,我看到它使用一个随机MAC地址:

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

如何设置一个特定的MAC地址容器运行?

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

我可以同时运行多个容器同时运行MAC地址吗?这些容器不需要访问外部网络,不需要彼此通话。

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.

推荐答案

设置MAC地址使用LXC配置选项 lxc.network.hwaddr
以下是使用Docker 0.6.1设置MAC地址的示例:

The MAC address is set using the LXC configuration option lxc.network.hwaddr. Here is an example of how to set MAC address using Docker 0.6.1:

docker run --lxc-conf="lxc.network.hwaddr=92:20:de:b0:6b:61" my_image ifconfig

在输出中,您将看到设置的HWaddr:

In the output, you will see the HWaddr that was set:

eth0      Link encap:Ethernet  HWaddr 92:20:de:b0:6b:61

更新:

以前的开关 -lxc-conf (带有一个破折号)已被弃用。

The previous switch -lxc-conf (with 1 dash) has been deprecated.

要使用上述开关,坞坞必须使用LXC驱动程序: -e lxc

To use the above switch, you docker must be using the LXC driver: -e lxc

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

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