如何将主机的IP地址传递给Docker中的容器?
我的机器上有多个NIC,因此有多个外部可路由的IP地址。
当我启动一个容器时,我想让容器的虚拟eth0拥有我公开的IP地址之一的IP地址
这是因为我的每个应用程序都查询其本地IP并通过专有协议将其传递给外部,所以所有的iptables技巧都不能工作
我该怎么做呢?
我不确定这是不是一个好习惯,但是当你启动你的容器时你可以通过--net
选项:
docker run --net=host ...
从man docker run
:
--net="bridge" Set the Network mode for the container 'bridge': creates a new network stack for the container on the docker bridge 'none': no networking for this container 'container:': reuses another container network stack 'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.