【发布时间】:2014-10-21 04:04:36
【问题描述】:
我对 docker 默认给我的 IP 范围 176.17.x.x 非常满意,所以我不需要创建新的网桥,我只想给我的容器一个静态地址 within 该范围,因此我可以将客户端浏览器直接指向它。
我尝试使用
RUN echo "auto eth0" >> /etc/network/interfaces
RUN echo "iface eth0 inet static" >> /etc/network/interfaces
RUN echo "address 176.17.0.250" >> /etc/network/interfaces
RUN echo "netmask 255.255.0.0" >> /etc/network/interfaces
RUN ifdown eth0
RUN ifup eth0
来自 Dockerfile,它正确地填充了接口文件,但接口本身并没有改变。事实上,在容器内运行 ifup eth0 会得到这个错误:
RTNETLINK 回答:Operation not allowed 无法启动 eth0
【问题讨论】:
-
您可以尝试使用 --net=host 选项。然后容器将在主机的 IP 地址上可用。
-
谢谢马克。我重新编写了 Dockerfile 以使用我的静态 IP 设置一个名为 docker0(这是 --net=host 将创建的接口)的接口,构建映像并使用 --net=host 加载它。但是 docker0 仍然从 DHCP 获取它的 IP,并且 ifup docker0 仍然不起作用。
标签: linux networking docker