docker - 如何将主机的 IP 地址传递到 Docker 中的容器

标签 docker lxc

我的机器上有多个 NIC,因此有多个外部可路由 IP 地址。

当我启动一个容器时,我想让容器的虚拟 eth0 具有我公开可见的 IP 地址之一的 IP 地址

这是因为我的每个应用程序都查询其本地 IP 并通过专有协议(protocol)将其与外部通信,因此所有 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.

关于docker - 如何将主机的 IP 地址传递到 Docker 中的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24925265/

相关文章:

docker - 服务无法启动虚拟机 'DockerDesktopVM',因为其中一个 Hyper-V 组件未运行

linux - Newrelic 不显示 Docker 容器的 CPU 和内存使用情况

docker - 为什么 Dockerfile 中的相同 RUN 命令会导致镜像之间的层大小不同?

docker - 从主机连接 Docker 容器内的 webpack-dev-server

node.js - 有条件地检测 Node 服务器是否在 Docker 容器内运行

linux - lxc - Linux容器无法访问设备节点

ubuntu - lxd (ubuntu 16.10) 容器mac地址

linux - 构建 Docker 容器时出错

linux - 嵌入式 Linux 中的安全选项?

ssl - 使用 NGinx、LXD/LXC 和 Kong 的代理协议(protocol)