简体   繁体   English

如何将主机的IP地址传递给Docker中的容器

[英]How do I pass the host's IP address to my container in Docker

I have multiple NICs on my machine and hence multiple externally routable IP addresses. 我的计算机上有多个NIC,因此有多个可外部路由的IP地址。

When I start a container, I want to make the container's virtual eth0 have the IP address of one of my publically visible IP addresses 当我启动容器时,我想让容器的虚拟eth0具有我公开可见的IP地址之一的IP地址

This is because each of my applications queries its local IP and communicates it to the outside over a proprietary protocol, so all of the iptables tricks wont work 这是因为我的每个应用程序都查询其本地IP并通过专有协议将其传递给外部,因此所有的iptables技巧都不会工作

How do I do this? 我该怎么做呢?

I'm not sure if it's a good practice, but you can pass --net option when you start your container: 我不确定这是不是一个好习惯,但你可以在启动容器时传递--net选项:

docker run --net=host ...

From man docker run : 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将主机 IP 地址传递给 docker 容器 - How do you pass in host IP address to docker container 如何从主机访问 Docker 容器的内部 IP 地址? - How to access Docker container's internal IP address from host? 如何从主机获取 Docker 容器的 IP 地址 - How to get a Docker container's IP address from the host 如何从 Windows 主机获取 Docker 容器的 IP 地址 - How to get a Docker container's IP address from the Windows host 如何使Eureka客户端使用主机的IP而不是Docker容器的IP? - How do I make Eureka client to use host machine's IP instead of Docker container's IP? 如何将主机 IP 地址传递给 Docker 撰写文件? - How can I pass host IP address to Docker Compose file? 如何为Windows容器给docker分配一个自己的IP地址? - How do I give an own ip address to docker for Windows container? 如何将Eureka服务ip传递给在docker容器中运行的java应用程序? - How do I pass Eureka service ip to my java application running in a docker container? 如何从 Windows 主机获取位于桥接网络内的 Docker 容器的 IP 地址? - How to get a Docker container's IP address, located within a bridge network, from a windows host? 如何从容器化的 angular 应用程序中访问我的 docker 主机的 IP - How do I access my docker host machine's IP from within an angular app that is containerized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM