ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Docker: gazebo: cannot connect to X server

asked 2019-06-24 10:44:55 -0600

aarontan gravatar image

updated 2022-10-30 09:28:29 -0600

lucasw gravatar image

Hello,

I am running a dockerfile which I pulled from this link.

Inside this dockerfile, there is a gazebo launch file which I am trying to launch.

However, I receive the following error message when I try to launch it with the following command:

roslaunch simulate_traversability_core launch_simulations.launch world_name:=custom1 dataset_type:=training number_tries:=50

The error message:

[Err] [RenderEngine.cc:699] Can't open display: 
[Wrn] [RenderEngine.cc:97] Unable to create X window. Rendering will be disabled
[Wrn] [RenderEngine.cc:301] Cannot initialize render engine since render path type is NONE. Ignore this warning ifrendering has been turned off on purpose.
[Wrn] [ModelDatabase.cc:339] Getting models from[http://gazebosim.org/models/]. This may take a few seconds.
process[gazebo_gui-5]: started with pid [441]
gazeb: cannot connect to X server 
[gazebo_gui-5] process has died [pid 441, exit code 1, cmd /opt/ros/kinetic/lib/gazebo_ros/gzclient __name:=gazebo_gui __log:=/root/.ros/log/5e340b88-9694-11e9-b6ab-0242ac110003/gazebo_gui-5.log].
log file: /root/.ros/log/5e340b88-9694-11e9-b6ab-0242ac110003/gazebo_gui-5*.log

I assume that this has something to do with the xserver so I have tried following this tutorial.

I am trying to make the "Simple way" work; however, I am not sure how to connect the dockerfile i am interested in with the xserver based on what is described in the tutorial.

Does anyone have any experience similar to this?

Regards, Aaron

Edit 1:

By following the Docker GUI Tutorial

I have typed the following in the command window

docker run -it \
    --env="DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    romarcg/traversability-ros-ubuntu-gazebo \
    rqt
export containerId=$(docker ps -l -q)

Afterwards, in the same window, I entered the following as suggested by "The Simple Way" in the tutorial.

xhost +local:root

I am still unable to see the gazebo gui. Currently receiving the same error message.

edit retag flag offensive close merge delete

Comments

Another option is to run gzserver in the docker image, and gzclient on your host machine. You'll need to export a Gazebo master uri to point to your docker instance first, then start gzclient.

ChuiV gravatar image ChuiV  ( 2019-06-24 10:52:17 -0600 )edit

@ChuiV thanks for your suggestion, could you please provide some more insight in implementing this alternative solution?

aarontan gravatar image aarontan  ( 2019-06-24 11:02:39 -0600 )edit

Unfortunately I can't seem to find the tutorial for it anymore. However this answer might help get you going in the right direction. Essentially you need to start your docker image, (get it's IP address) set the GAZEBO_MASTER_URI (Sorry, I don't remember/can't find exactly what this needs to be.) and start gzclient in the same terminal.

Yet another option is to setup gzweb (http://gazebosim.org/tutorials?tut=gz...) in your docker image.

You might have better answers over on answers.gazebosim.org It's been several months since I've done this, and I can't remember the exact details. Sorry!

ChuiV gravatar image ChuiV  ( 2019-06-24 11:17:56 -0600 )edit

Thank you for your suggestion.

I have opened up a new question regarding my attempt in this direction.

aarontan gravatar image aarontan  ( 2019-06-24 14:14:29 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-06 15:25:55 -0600

chives_onion gravatar image

I'm unsure of your setup, but I was able to solve a similar issue with uninstalling Docker Desktop and installing Docker CE. I have Ubuntu 22 as my host OS and apparently Docker Desktop on Ubuntu runs through a VM that doesn't properly forward graphics access. This thread covers the issue as related to USB connections.

For additional reference: I did not need to run the command xhost +local:root but did need to run xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f /tmp/.docker.xauth nmerge - && chmod 644 /tmp/.docker.xauth. I'm working with Gazebo Fortress and ROS2 Humble.

I used the following compose file to launch the container:

version: '3.4'

networks:
  ros_net:
    driver: bridge

services:
  gazebo:
    image: [your gazebo image]
    command: ign gazebo empty.sdf
    environment:
      - DISPLAY=${DISPLAY}
      - QT_X11_NO_MITSHM=1    
      - QT_DEBUG_PLUGINS=1
      - XAUTHORITY=/tmp/.docker.xauth  
    networks:
      - ros_net      
    volumes:
      - ~/.gazebo:/root/.gazebo/:rw   
      - /tmp/.X11-unix:/tmp/.X11-unix:rw
      - /tmp/.docker.xauth:/tmp/.docker.xauth:rw" 
      - "/dev/dri:/dev/dri"
edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2019-06-24 10:44:55 -0600

Seen: 4,933 times

Last updated: Jun 06 '23