I just started using docker and I need to use it to run ros melodic. I am currently on ubuntu 22.04.
The dockerfile I am using to create an image is the following:
FROM osrf/ros:melodic-desktop-full
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update &&
apt install -y --no-install-recommends
software-properties-common
ros-melodic-catkin
python-catkin-tools
python-pip
openssh-client
net-tools
ros-melodic-rqt-multiplot
x11-apps
&& rm -rf /var/lib/apt/lists/*
I build it with docker build -t e-go:latest .
. Everythigh looks good so far.
To run the container I made a bash file:
#! /bin/bash
xhost +local:
docker run -it --rm
--net=host
--user=$(id -u)
--env="ROS_HOME=/home/$USER/.ros"
-e DISPLAY=$DISPLAY
-e QT_GRAPHICSSYSTEM=native
-e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR
--env="QT_X11_NO_MITSHM=1"
-e CONTAINER_NAME=ros-melodic-dev
-e USER=$USER
--workdir=/home/$USER
-v "/tmp/.X11-unix:/tmp/.X11-unix"
-v "/etc/group:/etc/group:ro"
-v "/etc/passwd:/etc/passwd:ro"
-v "/etc/shadow:/etc/shadow:ro"
-v "/etc/sudoers.d:/etc/sudoers.d:ro"
-v "/home/$USER/:/home/$USER/"
-v "/run/user/1000:/run/user/1000"
-v "$HOME/.ros:/home/$USER/.ros"
--device=/dev/dri:/dev/dri
--name=ros-melodic-dev
--privileged
e-go:latest
After it in the first terminal window inside the container I run roscore
and it works fine. In a new terminal I run source /opt/ros/melodic/setup.bash
, then to test the GUI in docker I run rosrun turtlesim turtlesim_node
. This last command gives me the following error:
QStandardPaths: wrong ownership on runtime directory /run/user/1000, 0 instead of 1000
qt.qpa.screen: QXcbConnection: Could not connect to display :1
Could not connect to any X display.
I tried almost all the suggestions online, but nothing worked. Another thing I tried was to run the container as root user with --user root
, in this case the error is slightly different:
qt.qpa.screen: QXcbConnection: Could not connect to display :0
Could not connect to any X display.
If you have any ideas it would be very helpful. If you need more information, I’ll be happy to provide it.
I tried to change xhost +local:
to xhost +local:docker
or xhost +local:root
.
I added
--ipc=host
--env=QT_X11_NO_MITSHM=1
--env=XAUTHORITY=$XAUTHORITY
-v /dev:/dev
To solve problems with X servers (did not worked).
And many other test that I don’t remember anymore…
2
Answers
You might want to try docker-compose file instead of bash (or you can translate back to bash command)
This is my
docker-compose.yml
file I successfully use with GUI located in the same folder as Dockerfile:O you could try removing
-v "/run/user/1000:/run/user/1000"
from your setup I remember this line was problematic for other reasonsIf I remember correctly on Windows something as simple as this was enough for GUI but it probably won’t work on Ubuntu:
For me the GUI works (
Ubuntu 20.04
) if I just:run this in the same terminal:
xhost +
and then add the following options to the
docker run
command:-e DISPLAY=$DISPLAY --device=/dev/video0:/dev/video0 -v /tmp/.X11-unix:/tmp/.X11-unix
and also--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
if it’s not working only with the previous ones.Not sure what might be the problem in your case, but I’m thinking it might be the missing
--device
option.