Not being able to link two services

We are setting up a docker compose where two services needs to communicate through the port 8888 using the udp protocol but we haven’t figured out how to set it up properly, we’ve tried depends_on, networking, expose but none of them have worked so far


networks:
  emp-network:

services:
  simulation:
    image: px4io/px4-dev-ros2-foxy:latest
    container_name: px4
    tty: true
    volumes:
      - ./:/src/PX4-Autopilot/:rw
      - /tmp/.X11-unix:/tmp/.X11-unix:ro
    privileged: true
    networks:
      - emp-network
    environment:
      - DISPLAY=:0
  uxrce:
    build:
      context: .
      dockerfile: xrce.Dockerfile
    image: ubuntu-xrcedds-suite
    container_name: uxrcedds
    tty: true
    networks:
      - emp-network

Hi

Depends on is more a priority of which the containers should start, expose/port mapping would not be needed if its the 2 containers that need to communicate.

networking on the other hand is important, they need to be one the same docker network.

How do you tell container-1 that it needs to contact container-2, is there a config or something that defines this?

The correct way would be to use the containers internal name, in the network.
so fx. if you want simulation to contact uxrce, you should use “uxrce” as host name

Thanks!
I was needing to launch an agent and a client, the client running on the simulation service and the agent on the xrce service, so I solved it using the right hostname as you suggested replacing this line of code

uxrce_dds_client start -t udp -h uxrce -p $uxrce_dds_port $uxrce_dds_ns

the previous one was

uxrce_dds_client start -t udp -h 127.0.0.1 -p $uxrce_dds_port $uxrce_dds_ns

I was stuck on it since yesterday, thanks again!