Not sure if this is a problem in all cases, but it seems that when ROS 2 nodes communicate in two Docker containers with net=host, they see that they are running on the same computer and default to Shared Memory (SHM) transport. This does not work by default, and some extra configuration is needed.
See: