You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不同Docker容器间micro-ROS数据无法接收问题排查求助

跨Docker容器的micro-ROS与ROS2通信故障排查

我尝试在micro-ROS Docker容器中发布数据,在ROS2 Humble Docker容器中接收,自行编写了Dockerfile和docker-compose.yaml,但监听器无法接收数据,执行ros2 topic list也看不到ping_pong发布的话题。只有在同一容器内运行所有组件时才能正常工作,怀疑Agent接收了发布者数据但未转发。

提供的配置文件

Dockerfile

# Download base image ubuntu 22.04
FROM ubuntu:22.04

# LABEL about the custom image
LABEL maintainer="VV"
LABEL version="1.0"
LABEL description="This is a ROS2_pub_sub Docker Image"

# Define build arguments
ARG TIME_ZONE
ARG DEBIAN_FRONTEND=noninteractive
ARG ROS_DISTRO=humble
#ARG DEBIAN_FRONTEND=noninteractive -> no user input needed when building

# Install dependencies
RUN apt-get update && \
    apt-get install -y locales\
    curl\
    locales\
    python3-pip\
 && rm -rf /var/lib/apt/lists/*

# Generate and set locales
RUN locale-gen en_US en_US.UTF-8 && \
    update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

# Set environment variables
ENV TZ=Europe/Berlin
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV ROS_VERSION=2
ENV ROS_DISTRO=humble
ENV ROS_PYTHON_VERSION=3
ENV RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity} {time}]: {message}"

# Add, install and source ROS2 humble
RUN apt-get update && apt-get install -y software-properties-common curl && \
    add-apt-repository universe

RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

# Install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    nano \
    iputils-ping \
    wget \
    python3-colcon-common-extensions \
    python3-colcon-mixin \
    python3-rosdep \
    python3-vcstool \
    git \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get upgrade -y &&\
    apt-get install -y ros-humble-desktop\
    && rm -rf /var/lib/apt/lists/*

RUN mkdir /microros_ws
WORKDIR /microros_ws
RUN git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup

RUN bash -c "source /opt/ros/humble/setup.bash"

# bootstrap rosdep
RUN rosdep init && \
  rosdep update --rosdistro humble  
RUN apt update && rosdep update
RUN rosdep install -i --from-path src --rosdistro humble -y

RUN bash -c "source /opt/ros/humble/setup.bash && \
            colcon build && \
            source install/local_setup.bash && \
            ros2 run micro_ros_setup create_firmware_ws.sh host && \
            ros2 run micro_ros_setup build_firmware.sh && \
            source install/local_setup.bash && \
            ros2 run micro_ros_setup create_agent_ws.sh && \
            ros2 run micro_ros_setup build_agent.sh && \
            source install/local_setup.bash"

# Environment setup
#RUN echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc
RUN echo '#!/usr/bin/env bash' > /ros_entrypoint.sh
RUN echo 'source /opt/ros/humble/setup.bash' >> /ros_entrypoint.sh
RUN echo 'source /microros_ws/install/local_setup.bash' >> /ros_entrypoint.sh

# Finalize entrypoint script
RUN echo 'exec "$@"' >> /ros_entrypoint.sh
RUN chmod +x /ros_entrypoint.sh

ENTRYPOINT ["/ros_entrypoint.sh"]

# Run command
CMD ["bash"]

docker-compose.yaml

version: "3"
services:
  micro_ros_agent:
    image: micro_ros_image.v1:latest
    volumes:
      - /dev/shm:/dev/shm
    network_mode: "host"
    environment:
      - ROS_DOMAIN_ID=33
    privileged: true
    command: ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 
    
  micro_ros_dds:
    image: micro_ros_image.v1:latest
    volumes:
      - /dev/shm:/dev/shm
    network_mode: "host"
    environment:
      - ROS_DOMAIN_ID=33
      - RMW_IMPLEMENTATION=rmw_microxrcedds
    privileged: true
    command: ros2 run micro_ros_demos_rclc ping_pong 
    
  micro_ros_listen:
    image: micro_ros_image.v1:latest
    volumes:
      - /dev/shm:/dev/shm
    network_mode: "host"
    environment:
      - ROS_DOMAIN_ID=33
    privileged: true
    command: ros2 topic echo /microROS/ping

排查与解决思路

1. 验证Agent与micro-ROS节点的连接状态

  • 进入micro_ros_agent容器,执行ros2 node list,确认是否能看到ping_pong节点。如果看不到,说明micro-ROS节点未成功连接Agent。
  • 查看ping_pong容器的日志,检查是否有连接失败的报错。micro-ROS默认尝试连接localhost:8888,可在micro_ros_dds容器的环境变量中添加MICROROS_AGENT_ADDRESS=127.0.0.1:8888,明确指定Agent地址。

2. 统一RMW实现配置

  • 当前仅发布者容器使用rmw_microxrcedds,Agent和监听容器使用默认RMW(可能为rmw_fastrtps_cpp),micro-ROS Agent需要与ROS2生态的RMW兼容:
    • 给所有容器设置统一的RMW实现,比如给监听容器添加RMW_IMPLEMENTATION=rmw_microxrcedds,或改用rmw_cyclonedds_cpp并确保全容器一致。
    • 注意:micro-ROS Agent本身无需设置RMW,但ROS2节点(含监听节点)的RMW需与Agent的DDS桥接兼容。

3. 检查网络与环境变量一致性

  • 确认所有容器的ROS_DOMAIN_ID完全一致,包括数值和大小写。
  • 进入每个容器执行echo $ROS_DOMAIN_ID和echo $RMW_IMPLEMENTATION,验证环境变量是否正确传递。
  • 检查宿主机防火墙是否拦截8888端口的UDP通信,执行sudo ufw status查看规则,必要时开放端口:sudo ufw allow 8888/udp。

4. 调整Agent启动参数

  • 给Agent添加详细日志输出,方便排查:ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 -v6(-v6为最高日志级别),查看是否有数据接收但未转发的日志。
  • 指定Agent绑定地址为0.0.0.0,确保接收所有接口的连接:ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 -p 0.0.0.0。

5. 验证话题发现机制

  • 在监听容器中执行ros2 topic list --include-hidden-topics,查看是否存在相关的micro-ROS内部话题。
  • 尝试用自定义代码创建订阅者替代ros2 topic echo,排除工具本身的问题。

6. 检查Docker镜像构建完整性

  • 确认Dockerfile中micro-ROS的构建过程无报错,比如colcon build、build_agent.sh是否完成所有依赖安装。可重新构建镜像,查看构建日志中的警告或错误。
  • 尝试使用官方micro-ROS Agent镜像(如microros/micro-ros-agent:humble)替换自定义镜像,排除镜像构建问题。

内容的提问来源于stack exchange,提问作者Victor Velezmoro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 12:52:57