This is used to launch through docker compose both realsense camera node and webcam nodes.
Assume you want to run both a webcam node and a Realsense node in separate containers (i.e., each coming from a different Docker image/Dockerfile: one containing the webcam code and the other containing the Realsense code).
You can launch them either with two separate docker run commands or with Docker Compose.
However, in both cases, the topics published by each node are automatically visible to the other container only when run from the same laptop. Otherwise, if you want the nodes to communicate, you need additional configuration, such as:
- Using --network host mode
- Configuring the same ROS_DOMAIN_ID
This ensures that the ROS2 nodes across containers can see each other and exchange topics. The following is a minimal example:
version: "3.9"
services:
webcam:
image: webcam_ros2
devices:
- "/dev/video0:/dev/video0"
- "/dev/video1:/dev/video1"
command: >
ros2 launch webcam_pkg my_launch_file.py
video_device1:=/dev/video0
video_device2:=/dev/video1
realsense:
image: realsense_ros2
devices:
- "/dev/video2:/dev/video2"
command: >
ros2 launch realsense2_camera rs_launch_file.py-
Separate repositories/images:
One repo (or pre-built image) for the webcam node, containing its Dockerfile.
Another repo (or pre-built image) for the Realsense node, with its Dockerfile.
The other person either clones the repos and builds the images locally using docker build, or you provide pre-built images on Docker Hub/registry.
-
docker-compose folder:
In a separate, empty folder, you put just the docker-compose.yml that references those images.
The docker-compose.yml defines both services (webcam and Realsense), mounts devices, sets network mode, etc.
-
Running the setup:
From that folder, they run:
docker compose up
Compose will start two containers (or more if you define more nodes) based on the images.
-
To stop (and delete) containers activated through compose:
docker compose down
To launch your nodes and keep them running in the background, you can use compose in detached mode:
docker compose up -dThen you can open a shell in the running container whenever you want to digit new commands (rostopic list, roslaunch, ...):
docker compose exec webcam bashFor additional info, make reference to: