[英]How to access docker container in a custom network from another docker container running with host network
My program is consisting of a network of ROS1 and ROS2 nodes, which are software that work with a publish/subscribe way of communication.我的程序由 ROS1 和 ROS2 节点网络组成,它们是使用发布/订阅通信方式的软件。
Assume there is 4 nodes running inside a custom network: onboard_network.假设有 4 个节点在自定义网络中运行:onboard_network。
Those 4 nodes (ROS1) can only communicate together, therefore we have a bridge node (ROS1 & ROS2) that needs to be sitting on the edge on both onboard_network and host network.这 4 个节点(ROS1)只能一起通信,因此我们有一个桥节点(ROS1 和 ROS2)需要位于 onboard_network 和主机网络的边缘。 The reason why we need the host network is because the host is inside a VPN (Zerotier).
我们需要主机网络的原因是因为主机在VPN(Zerotier)内部。 Inside the VPN we have also our server (ROS2).
在 VPN 内部,我们还有我们的服务器 (ROS2)。
We also need the bride node to work with host network because ROS2 work with some multicast stuff that works only on host mode.我们还需要新娘节点与主机网络一起工作,因为 ROS2 可以处理一些仅在主机模式下工作的多播内容。
So basically, I want a docker compose file running 4 containers inside an onboard_network & a container running inside the host network.所以基本上,我想要一个 docker 组合文件,在 onboard_network 内运行 4 个容器,在主机网络内运行一个容器。 The last container needs to be seen from the containers in the onboard_network and being able to see them too.
最后一个容器需要从 onboard_network 中的容器中看到并且也能够看到它们。 How could I do it?
我怎么能做到? Is it even possible?
甚至可能吗?
If you're running a container on the host network, its network setup is identical to a non-container process running on the host.如果您在主机网络上运行容器,则其网络设置与在主机上运行的非容器进程相同。
A container can't be set to use both host networking and Docker networking.不能将容器设置为同时使用主机网络和 Docker 网络。
That means, for your network_mode: host
container, it can call other containers using localhost
as a hostname and their published ports:
(because its network is the host's network).这意味着,对于您的
network_mode: host
容器,它可以使用localhost
作为主机名及其发布的ports:
因为它的网络是主机的网络)。 For your bridge-network containers, they can call the host-network container using the special hostname host.docker.internal
on MacOS or Windows hosts, or on Linux they need to find some reachable IP address (this is discussed further in From inside of a Docker container, how do I connect to the localhost of the machine? . For your bridge-network containers, they can call the host-network container using the special hostname
host.docker.internal
on MacOS or Windows hosts, or on Linux they need to find some reachable IP address (this is discussed further in From inside of一个 Docker 容器,我如何连接到机器的本地主机? 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.