How to share the UDP port of a container with app container (Both are in the same compose.yml file)

Hi,
I made the image of my Django app with a docker file. Then I used that image in my docker-compose.yml file.

Here is my docker-compose file:

services:
  redis:
    image: redis
    container_name: redis

  app:
    build: .
    ports:
      - 8000:8000
    volumes: 
      - type: bind 
        source: /home/user/mydjangodirectory
        target: /mydjangodirectory
    image: mydjangoproj:1.0.0
    container_name: djangoapp-container
    command: python manage.py runserver 0.0.0.0:8000

  celery-beat:
    restart: always
    build:
      context: .
    command: celery -A djangoproj beat -l INFO
    volumes: 
      - type: bind 
        source: /home/user/mydjangodirectory
        target: /mydjangodirectory
    depends_on:
      - redis
      - app

  celery-worker:
    restart: always
    build:
      context: .
    command: celery -A djangoproj worker -l INFO
    volumes: 
      - type: bind 
        source: /home/user/mydjangodirectory
        target: /mydjangodirectory
    depends_on:
      - redis
      - app
      - celery-beat

  simulator:
    image: jonasvautherin/px4-gazebo-headless
    ports:
      - 14540:14540
    depends_on:
      - app

The last service “simulator” is exposing port 14540 to the outside world that is being used by my app.
When I run the simulator in docker on my host machine and run the app on my host machine, everything works fine. But when I put these images in my docker-compose file and do the docker compose up, my app is working, celery, redis and simulator are also working. But simulator isn’t connecting with my app.

I corrected your title, as you mend container, but wrote image. Furthermore, please use a “preformated Text” block, instead of a quote block when posting code. This time I changed it for you.

I highly suggest taking a look at the compose file specifications if a configuration element is unclear:
https://docs.docker.com/compose/compose-file/#ports

If not specified, a published port will always use tcp, you need to explicitly specify it with /udp after the container port (see link above for details)

@meyay Thank you for all the help with the formating of my question.
As you suggested, I added the protocol to the port, but still no connection is made.
Here is the code after adding the protocol.

services:
  redis:
    image: redis
    container_name: redis

  app:
    build: .
    ports:
      - "8000:8000"
    volumes: 
      - type: bind 
        source: /home/user/mydjangodirectory
        target: /mydjangodirectory
    image: mydjangoproj:1.0.0
    container_name: djangoapp-container
    command: python manage.py runserver 0.0.0.0:8000

  celery-beat:
    restart: always
    build:
      context: .
    command: celery -A djangoproj beat -l INFO
    volumes: 
      - type: bind 
        source: /home/user/mydjangodirectory
        target: /mydjangodirectory
    depends_on:
      - redis
      - app

  celery-worker:
    restart: always
    build:
      context: .
    command: celery -A djangoproj worker -l INFO
    volumes: 
      - type: bind 
        source: /home/user/mydjangodirectory
        target: /mydjangodirectory
    depends_on:
      - redis
      - app
      - celery-beat

  simulator:
    image: jonasvautherin/px4-gazebo-headless
    ports:
      - "14540:14540/udp"
    depends_on:
      - app

I tried adding the udp before also as I read this in an article, but this didn’t work (added the double quotes in the ports as suggested on the documenation link you gave).

After running the entire docker, I ran the netstat -tunlp on the simulator and app containers with the hope that it might help you give some more information that you can use to help me fix my problem. Output image is attached.

To share the maximum information, here is the code of my app source file which is using the simulator for connection:

app file:

#!/usr/bin/env python3

import asyncio
from mavsdk import System


async def run():
    # Init the drone
    drone = System()
    await drone.connect(system_address="udp://:14540")

    print("Waiting for drone to connect...")
    async for state in drone.core.connection_state():
        if state.is_connected:
            print(f"-- Connected to drone!")
            break

    # Execute the maneuvers
    print("-- Arming")
    await drone.action.arm()

    print("-- Taking off")
    await drone.action.set_takeoff_altitude(10.0)
    await drone.action.takeoff()

    await asyncio.sleep(10)

    print("-- Landing")
    await drone.action.land()


if __name__ == "__main__":
    # Run the asyncio loop
    asyncio.run(run())

In my code I tried the following things, but none of them worked:
Approach # 1- await drone.connect(system_address="udp://:14540")
Approach # 2- await drone.connect(system_address="udp://localhost:14540")
Approach # 3- await drone.connect(system_address="udp://simulator:14540") (name of the service)