ros-ukraine / leobot

LeoBot telepresence robot
MIT License
21 stars 4 forks source link

Starting a GUI application from docker container #83

Open MaxZhaloba opened 6 years ago

MaxZhaloba commented 6 years ago

I have a task to run render a URDF file using this tutorial: http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20with%20URDF%20from%20Scratch. I faced several issues when trying to accomplish it, so I want to share my solutions with the comunity.

I've tried to use the ROS docker containers as described here: http://wiki.ros.org/docker/Tutorials/Docker.

Here are the steps I've taken:

  1. Downloaded the ROS docker image docker pull ros:kinetic-robot-xenial
  2. Tried to start the container with regular commands docker run -it ros and connect to it in new terminal window using docker exec -it <container_name> bash. In this case, terminal commands were wrapping to the same line and overwrote the beginning of the command, so I couldn't actually see the entire command and the terminal ended up rather unusable for me. As I found out, it happened because of this issue: https://unix.stackexchange.com/a/264236

So I decided to install Terminator within the docker container. This requires some additional steps to make it connect to the host X window environment. Here's my solution.

  1. Delete the existing container created from ros image (of you created any) with docker container rm <container_name>

  2. Create a new container passing the environment variables and virtual FS (copied from LeoBot): docker run -it -e DISPLAY -e LOCAL_USER_ID=$(id -u) -v /tmp/.X11-unix:/tmp/.X11-unix:rw ros Triggering printenv in docker container should list the variables you passed. During this step, when container is running, you can establish a new connection to it by finding out the container name docker container list and connecting with docker exec -it <container_name> bash.

  3. When you try to install any program inside the container (e.g. apt-get install terminator) apt will fail:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package terminator

For some reason this container comes with no preconfigured application repository, so you need to add one apt-get -qq update and then apt-get install terminator.

Then, when you try to start the terminator from container, it will fail with such message:

root@55d1d562bb95:/# terminator
No protocol specified
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
You need to run terminator in an X environment. Make sure $DISPLAY is properly set

If you passed the parameters when creating this container using docker run, the remaining bit of configuration is to allow connections to X window system on your local machine, i.e. run xhost local:root on your host. After this, it should be possible to launch the terminator from container, even without restarting it.

Other useful commands:

List all docker containers (running and stopped): docker container list -a Each time you trigger docker run, it creates a new container, so it's a good idea to:

Delete the container using name or ID from previous command: docker container rm <container_name>

More info on ROS docker images: https://store.docker.com/images/ros https://hub.docker.com/_/ros/

AndriyPt commented 6 years ago

please use Leobot's docker :)