可以为docker build设置一个MAC地址吗? [英] Is it possible to set a MAC address for `docker build`?
问题描述
使用docker run
,可以使用--mac-address
选项修复MAC地址.我已经查看过,但找不到用docker build
修复MAC地址的方法.我想将具有固定在MAC地址上的许可证的软件码头化(我不打算散布许可证;我想要的是更具可复制性的系统架构).
With docker run
, it’s possible to fix the MAC address with the --mac-address
option. I’ve looked, and I can’t find a way to fix the MAC address with docker build
. I am wanting to dockerize software that has a license fixed to a MAC address (I’m not trying to get around the license; I’m trying to have a more reproducible system architecture).
谢谢!
推荐答案
让我们考虑以下Dockerfile
Let's consider the below Dockerfile
FROM alpine
RUN ifconfig | grep -i hwaddr
如果您使用它构建
docker build .
你得到
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM alpine
---> 7328f6f8b418
Step 2/2 : RUN ifconfig | grep -i hwaddr
---> Running in c092838dbe31
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
Removing intermediate container c092838dbe31
---> 7038787f51b8
现在我们无法控制docker build的Mac地址,但是我们可以控制build的网络,也可以控制容器的mac地址.因此,让我们用我们的mac地址启动一个容器
Now we can't control Mac address of docker build, but we can control the network of build and we can control mac address of a container. So let us launch a container with our mac address
$ docker run --name mac1234deb06b61 --mac-address="12:34:de:b0:6b:61" -d alpine tail -f /dev/null
c3579e4685933b757f51c5f9e36d620dbe3a62abd0e0d6a421b5f1c04045061c
$ docker build --network container:mac1234deb06b61 --no-cache .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM alpine
---> 7328f6f8b418
Step 2/2 : RUN ifconfig | grep -i hwaddr
---> Running in 4390f13cbe8f
eth0 Link encap:Ethernet HWaddr 12:34:DE:B0:6B:61
Removing intermediate container 4390f13cbe8f
---> b0b5f7321921
Successfully built b0b5f7321921
如您所见,现在docker构建采用了更新的mac地址
As you can see, now the docker build takes a updated mac address
这篇关于可以为docker build设置一个MAC地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!