skip to Main Content

I attempted to learn how to develop ROS2 in Docker, so I started with this tutorial: link to the tutorial. Everything seemed fine until I tried to establish communication between a talker-listener pair running in separate Docker containers and the host machine. They couldn’t see each other’s topics. Here’s my Dockerfile for reference.

FROM osrf/ros:humble-desktop
ARG USERNAME=jarunyawat
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME 
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME 
    #
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update 
    && apt-get install -y sudo 
    && echo $USERNAME ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME 
    && chmod 0440 /etc/sudoers.d/$USERNAME
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y python3-pip
ENV SHELL /bin/bash
ENV ROS_DOMAIN_ID 42
ENV ROS_LOCALHOST_ONLY 0
ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME
CMD ["/bin/bash"]

build the image and run this command

docker run -it --network=host --ipc=host --pid=host ros2-dev-wat:lastest

In the host terminal, I ran the talker demo node, and in the container terminal, I attempted to list topics. However, the container could not detect the /chatter topic. MY ROS_LOCALHOST_ONLY is set to 0 and ROS_DOMAIN_ID is set to 42 in my host. So, i attempted to run above command with talker node and in the other terminal I run above command with talker node. It couldn’t communicate with each other. It appears that the issue is related to the use of the Docker options –network=host –ipc=host –pid=host.

I expected the container to be able to communicate with the host.

2

Answers


  1. Chosen as BEST ANSWER

    It appear that the problem come from docker desktop on ubuntu. wWen I removed docker desktop everything work as expect.


  2. i did not had time to test it but, make sure your env variables set for correct user in container. maybe put user directive before env directives

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search