Ping between containers in separate docker networks?


I’m trying to “simulate” a setup of two separate Linux machines under the same WiFi network.

This is to showcase some features in ROS 2 (Robot Operating System) that happen when trying to communicate two robots.

I have two containers, each under their own network:

  1. container 1 - network 1 (
  2. container 2 - network 2 (

I don’t want to create a 3rd bridge network like it was suggested in this post: Ping container in different network on the same docker host using DOCKER-USER?, because that would defeat the purpose of my “simulation” of separate machines, each with their own IP.

What can I do so I can ping container 1 from container 2 and vice-versa?

Containers in different custom docker networks can’t communicate so the only way as far as I know is having a common network for both containers.

I don’t really understand the issue as you mention emulating machines " under the same WIFI network" so you don’t need multiple networks.

A single Docker network doesn’t mean the containers won’t have their own IP address. They will have, but they will be in the same subnet so they can communicate.

What you probably thought is using the same network namespace, which would mean two containers have the same “localhost” as well, but by default each container has its own IP on the network.

1 Like

Thank you for your answer.

I realize my mistake now, I didn’t know they would have their own IP address under the same network. I wasn’t understanding the setup I wanted correctly.

I will set it back to a single docker network and work with that.