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

ROS environment in Docker with X11

asked 2022-10-08 22:07:43 -0500

karlhm76 gravatar image

Hi,

This seems to be a fairly complicated thing to do. I want to set up a docker ROS development environment with catkin I am running ubuntu focal as my base environment

I have downloaded the osrf/ros:noetic-desktop-full image and I have been able to successfully run this as a container and perform a catkin_make. I can build projects on it from a container command line

I think I am pretty close to being able to get vscode working on it as well.

however I have not been able to get X11 output on it. I have followed the examples here and here

the problems I am having is when I try and run the docker image and create the container I receive these errors:

docker run -dt --name robot_env --restart unless-stopped -v 'pwd':/root/workspace --device=/dev/dri --volume=/tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY osrf/ros:noetic-desktop-full

e41c569191ad1799917f27384025826b987951de46b12d64a7295d59892aa23c
docker: Error response from daemon: Mounts denied: 
The path /tmp/.X11-unix is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/ for more info.

and when I remove the volume to /tmp/.X11-unix and try, I receive this error

docker run -dt --name robot_env --restart unless-stopped -v 'pwd':/root/workspace --device=/dev/dri -e DISPLAY osrf/ros:noetic-desktop-full
8ed2a58fb0bdd6c76e9ee6d9022542011d06df24f10cf8a88a1edf1bb0f5a504
docker: Error response from daemon: error gathering device information while adding custom device "/dev/dri": no such file or directory.

Regrading the device issue, it may just be a case of not knowing what the device name is that I need to add

but the /tmp/.X11-unix problem seems like there is something missing on my install? Perhaps this is relevent to windows systems? Permissions? I'm not sure.

I checked and I do have a /tmp/.X11-unix folder so maybe it is permissions?

anyone know how to get X11 output working?

thanks in advance

edit retag flag offensive close merge delete

Comments

Are you using focal desktop or server? And are you remotely connecting to the development computer, or direct? VM by any chance?

PointCloud gravatar image PointCloud  ( 2022-10-09 02:06:35 -0500 )edit
1

I checked and I do have a /tmp/.X11-unix folder so maybe it is permissions?

Have you tried running your command as sudo to see if it was permissions related ?

anyone know how to get X11 output working?

Both these tutorial start with "using rocker". Have you tried using it ? The following works for me: rocker osrf/ros:noetic-desktop-full bash --x11

marguedas gravatar image marguedas  ( 2022-10-09 02:19:13 -0500 )edit

Hi, everything exists on the same machine running focal desktop clean install. I have installed build-essential and docker only. To connect to the docker container I use docker exec .. bin/bash.

To create the docker container I used the docker run command (without the X11 stuff.)

I believe vscode opens a remote "container" to it, but that's a different thing, and seems to be coincidental nomenclature.

At the moment I would be happy just to get glxgears working from a docker terminal.

(glxgears works fine locally as well.)

karlhm76 gravatar image karlhm76  ( 2022-10-09 02:19:56 -0500 )edit

I'll give rocker a try now and see how I go, thanks.

karlhm76 gravatar image karlhm76  ( 2022-10-09 02:20:45 -0500 )edit

ADE is another option to setup and run a Docker based dev environment with GUI support. There is also a vscode volume available that can be loaded alongside it.

sgvandijk gravatar image sgvandijk  ( 2022-10-09 05:03:02 -0500 )edit

@marguedas Thanks for this. I was able to install rocker and running your command got it to build the image, but it seems that it built the image in the default context.

I'll see whether I can get it to build it in the desktop-linux context, but it looks promising.

karlhm76 gravatar image karlhm76  ( 2022-10-15 22:59:59 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-10-16 12:45:33 -0500

gentijo gravatar image

Here is link to my repo where I have Docker definitions and start scripts to run Docker ROS apps on the host's XWin server. I mainly use a Linux host, but I also include start scripts for Windows and Mac OS.

Docs in the README.md https://github.com/gentijo/MaqueenBat...

edit flag offensive delete link more
0

answered 2022-10-16 04:29:26 -0500

karlhm76 gravatar image

updated 2022-10-16 04:42:00 -0500

Ok. It took some doing but I was able to get it to work, at least, glxgears works inside a docker container and renders correctly.

it may not be the best way to get it to work, but it works.

  1. using the suggestion from @marguedas I set up rocker. This needed the additional dependency of python3-distutils to work correctly. To be able to set up rocker I needed to add the ros repos to my base ubuntu install.

  2. I ran the command above for rocker to create the docker image from the osrf/ros:noetic-desktop-full image. I could not solve the problem that rocker creates this image in the default context. I had to change my docker context to the default context prior to running the rocker command otherwise it can not find the image when it runs docker run

  3. The default container created by rocker is no good, but helpfully it does echo the docker run command it uses. So I made another one following advice from here

The final container I created was set up using this command:

docker run --privileged --restart unless-stopped -dt --name robot_env -e DISPLAY -e TERM   -e QT_X11_NO_MITSHM=1   -e XAUTHORITY=/tmp/.dockermsrl4g3x.xauth -v /tmp/.dockermsrl4g3x.xauth:/tmp/.dockermsrl4g3x.xauth   -v /tmp/.X11-unix:/tmp/.X11-unix   -v /etc/localtime:/etc/localtime:ro  -v `pwd`:/root/workspace  7612d078aead

where 7612d078aead is the id of the image created by rocker

Note the --privileged option, this is required to be able to map the /dev/dri to the docker container. There may be a better way, but this works.

this command will also create a volume of my pwd and map it to /root/workspace in my container

I have followed the ROS Wiki and used xhost + to remove permissions to the X server, but I have seen better ways of doing this. For now I just want to get it working.

After setting up this container I am able to connect to it using:

docker exec -it robot_env bash.

Inside the container I am able to run (requires installing mesa-utils):

glxinfo | grep Mesa

and it can find my graphics card (Intel).

glxgears works and is accelerated.

Some things I would like to have but have not been able to figure out yet are:

create the rocker image in my preferred docker context so I can manage it with the docker gui. Its not a huge deal, but it is just a bit nicer when most of the time I simply want to start and stop the container.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2022-10-08 22:07:43 -0500

Seen: 1,027 times

Last updated: Oct 16 '22