docker/lxc 桥接网络

docker/lxc 桥接网络

我有一台服务器(主机),它有 1000 个外部 IP 地址。我创建了一个运行 squid3 的 docker 容器,我需要使用这些 IP 地址。我可以从主机启用转发,但这只会将请求转发到本地 docker ip,这会搞砸我的 squid ACL,因为 squid 看到的是内部 IP,而不是外部 IP。

我的问题如下,如何使用 docker 或 lxc(docker 通过 -lxc-conf= 具有 lxc 指令),以便我可以在我的容器中看到主机的外部 ip 地址(例如运行 ifconfig)。现在 docker 以其自己的隔离网络启动,因此对我来说无法使用。

主机外部 IP 地址分配给接口 p1p1。

我尝试使用 -lxc-conf="lxc.network.type = phys" -lxc-conf="lxc.network.link = p1p1" 来运行它,但是这完全搞乱了我的主机界面,甚至将我踢出 ssh。

知道我做错了什么吗?

答案1

管道可以帮你。

Connect a container to a local physical interface

Let's pretend that you want to run two Hipache instances, listening on real interfaces eth2 and eth3, using specific (public) IP addresses. Easy!

pipework eth2 $(docker run -d hipache /usr/sbin/hipache) 50.19.169.157
pipework eth3 $(docker run -d hipache /usr/sbin/hipache) 107.22.140.5

Note that this will use macvlan subinterfaces, so you can actually put multiple containers on the same physical interface.

我想这就是你需要的。

相关内容