简体   繁体   English

如何从与主机网络一起运行的另一个 docker 容器访问自定义网络中的 docker 容器

[英]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.

相关问题 通过本地网络共享Docker容器并从其他主机访问它 - Share Docker container through local network and access to it from an another host 在 docker 容器中运行 ROS,并从同一 docker 网络(非主机网络)中的另一个 docker 容器中运行 ROS - Running ROS in docker container and echo/pub from another docker container within same docker network (non-host network) 如何从网络上的 docker 容器访问在本地主机上运行的网络服务器? - How to access webserver running on localhost from a docker container on a network? 如何将在boot2docker中运行的Docker容器连接到在另一台主机上运行的网络服务? - How do I connect a Docker container running in boot2docker to a network service running on another host? 如何从本地网络上的另一台机器访问Docker容器 - How to access docker container from another machine on local network 运行Docker容器时主机上无网络 - No network on host machine when running a Docker container 配置运行Docker容器的主机的网络接口 - Configure the network interfaces of the host a docker container is running on 在主机网络中运行的 docker 容器的 traefik 代理 - traefik proxy for docker container running in host network 如何从其他主机访问在MacOSX上运行的docker容器? - How to access a docker container running on MacOSX from another host? 使用 --network=host 在 MacOS 上运行 docker 容器时如何访问主机上的端口? - How to access a port on the host machine when running docker container on MacOS with --network=host?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM