0
$\begingroup$

Taking the image and the X server setting that you get from Docker on WSL2: how to test whether ROS gazebo can connect to already working X server (using its X11 window on Windows)?, I was curious how to use this ros-test container in docker-compose. And it turned out that that ros-test image was not enough, since you also need a catkin workspace on top of ROS. Here is the full Dockerfile to build the "ros-test" image:

FROM osrf/ros:kinetic-desktop-full
#ARG HOSTNAME

RUN apt-get update && \
    apt-get install -y dbus

RUN apt-get install -y mesa-utils libgl1-mesa-glx

ENV LIBGL_ALWAYS_INDIRECT=0
# "host.docker.internal" only works in Docker Desktop, on WSL distro, you will need to run with either
# your Windows computer name (like "DESKTOP-1234567") or with your Windows computer IP "xxx.xxx.xxx.xxx", for example:
# docker run -it --name ros-test -e DISPLAY=xxx.xxx.xxx.xxx:0.0 -e LIBGL_ALWAYS_INDIRECT=0 osrf/ros:kinetic-desktop-full bash
ENV DISPLAY=host.docker.internal:0.0 
#ENV DISPLAY=$HOSTNAME:0.0
#ENV DISPLAY=DESKTOP-1234567:0.0
#ENV DISPLAY=xxx.xxx.xxx.xxx:0.0

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python-catkin-tools

RUN /bin/bash -c 'source /opt/ros/kinetic/setup.bash &&\
    mkdir -p ~/catkin_ws/src &&\
    cd ~/catkin_ws/src &&\
    #catkin_init_workspace &&\
    cd ~/catkin_ws &&\
    catkin_make'

RUN bash -c "echo 'source ~/catkin_ws/devel/setup.bash' >> ~/.bashrc; \
    source ~/.bashrc"

For the docker-compose file to run, an ".env" file must be in the same directory as the "docker-compose.yml" (if you do not hard-code the environment variables).

# Along https://docs.docker.com/compose/environment-variables/, you can see the docker-compose with all ENV in it with:
#docker-compose config 

# To start, fill the .env file before with your DESTINATION_IP_OR_NAME, it is then loaded as a default for
#docker-compose up --build 

The ".env" file looks as follows:

# Find your Windows computer name by entering "hostname" in PowerShell
DESTINATION_IP_OR_NAME=DESKTOP-1234567

#or find your Windows Computer IP using "ipconfig" in PowerShell
#DESTINATION_IP_OR_NAME=xxx.xxx.xxx.xxx

# or if you use Docker Desktop, use:
#DISPLAY=host.docker.internal:0.0

# Should always be 0 if you want to use a Windows X server (standard case on WSL)
LIBGL_ALWAYS_INDIRECT=0

The docker-compose.yml then looks as follows (the image "ros-test" must already be built, or you need to put its Dockerfile in the same directory):

# https://wiki.ros.org/docker/Tutorials/Compose
version: '2.0'

networks:
  ros:
    driver: bridge

services:
  ros-master:
    image: ros-test
    command: stdbuf -o L roscore
    networks:
      - ros
    restart: always

  talker:
    image: ros-test
    depends_on:
      - ros-master
    environment:
      - "ROS_MASTER_URI=http://ros-master:11311"
      - "ROS_HOSTNAME=talker"
    #command: stdbuf -o L rostopic pub /chatter std_msgs/String "hello" -r 1
    command: bash -c "source ~/catkin_ws/devel/setup.bash && roslaunch gazebo worlds/pioneer2dx.world"
    networks:
      - ros
    restart: always

  listener:
    image: ros-test
    depends_on:
      - ros-master
    environment:
      #- "DISPLAY=DESKTOP-1234567:0.0"
      - "DISPLAY=${DESTINATION_IP_OR_NAME}:0.0"
      #- "LIBGL_ALWAYS_INDIRECT=0"  
      - "LIBGL_ALWAYS_INDIRECT=${LIBGL_ALWAYS_INDIRECT}"  
      - "ROS_MASTER_URI=http://ros-master:11311"
      - "ROS_HOSTNAME=listener"
    #command: stdbuf -o L rostopic echo /chatter
    # Choose command from http://gazebosim.org/tutorials?tut=ros_roslaunch#Exampleroslaunchcommand
    #command: bash -c "source ~/catkin_ws/devel/setup.bash && roslaunch gazebo_ros empty_world.launch"
    #command: bash -c "source ~/catkin_ws/devel/setup.bash && roslaunch gazebo_ros willowgarage_world.launch"
    #command: bash -c "source ~/catkin_ws/devel/setup.bash && roslaunch gazebo_ros mud_world.launch"
    #command: bash -c "source ~/catkin_ws/devel/setup.bash && roslaunch gazebo_ros shapes_world.launch"
    command: bash -c "source ~/catkin_ws/devel/setup.bash && roslaunch gazebo_ros rubble_world.launch"
    
    networks:
      - ros
    restart: always

This will open gazebo RViz on Windows.

In the easy test which is commented out, the talker (command: stdbuf -o L rostopic pub /chatter std_msgs/String "hello" -r 1) sends messages to the listener (command: stdbuf -o L rostopic echo /chatter). In the RViz test, the listener seems to get parameters and commands to show their effect as a gazebo RViz in the X11 display of a Windows X server, and I do not know what to send from the talker to the listener so that I can see something is changing in that listener's RViz.

The question:

  • When using the default ros-test image built from "osrf/ros:kinetic-desktop-full" and with the catkin workspace on top of it, is there a sort of demo "test talker" in the image? The roslaunch gazebo worlds/pioneer2dx.world shall be replaced by this "test talker" so that we can see something happening in the RViz window.
  • In other words, can the talker / listener setting be tested only with talker files that are already inside the image, or if not, how could a "test talker" be added?
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.