ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

docker: how to use RViz and Gazebo from a container?

asked 2018-08-08 23:32:48 -0600

muhammed rushid s gravatar image

updated 2018-08-09 03:32:28 -0600

bpinaya gravatar image

" sudo docker run -it osrf/ros:kinetic-desktop-full-xenial" it is working and roscore is also working , but "rosrun rviz rviz" is not working

i am using ubuntu 18.04 and ihave installed docker ,and i need to use ros kinetic , so for that i have pulled image of"osrf/ros:kinetic-desktop-full-xenial" but now im not able to use rviz and gazebo,how to install rviz and gazebo while using docker?

edit retag flag offensive close merge delete



Could you please use only a single sentence or question as title? (like the rest of the questions?) It does not make much sense to just paste the same text in both fields..

NEngelhard gravatar image NEngelhard  ( 2018-08-09 01:22:44 -0600 )edit

Please see if the information on the wiki/docker pages sheds some light on things.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-09 01:36:12 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted

answered 2020-07-02 09:28:24 -0600

JBruun gravatar image

Hi there, we got RViz to work through nvidia-docker2 (with OpenGL) by following the guide here:

We had to modify the script a bit to make it work:

# If not working, first do: sudo rm -rf /tmp/.docker.xauth
# It still not working, try running the script as root.


echo "Preparing Xauthority data..."
xauth_list=$(xauth nlist :0 | tail -n 1 | sed -e 's/^..../ffff/')
if [ ! -f $XAUTH ]; then
    if [ ! -z "$xauth_list" ]; then
        echo $xauth_list | xauth -f $XAUTH nmerge -
        touch $XAUTH
    chmod a+r $XAUTH

echo "Done."
echo ""
echo "Verifying file contents:"
file $XAUTH
echo "--> It should say \"X11 Xauthority data\"."
echo ""
echo "Permissions:"
ls -FAlh $XAUTH
echo ""
echo "Running docker..."

docker run -it \
    --env="DISPLAY=$DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    --env="XAUTHORITY=$XAUTH" \
    --volume="$XAUTH:$XAUTH" \
    --net=host \
    --privileged \
    --runtime=nvidia \
    our-nvidia-based-ros-melodic-image-plus-nvidia-env-vars-from-the-guide:latest \

echo "Done."

Note 1: We added the tail -n 1 into the xauth sequence since the original command resulted in two identical lines after the sed replacement. So we only took one of them.

Note 2: The --net=host and --privileged are only needed if you want to join the host pc network. We added it to test communication with RViz by playing a bag-file from the outside using rosbag play and seeing the images being received by RViz.

edit flag offensive delete link more


The link you provided for installing the nvidia-docker2 package was excellent thanks! I did find these instructions for installing the package easier to follow.

The provided script for running the container did not work for me. I had to rely on docker-compose to build the image and run the container. You can find the docker-compose.yml file I'm using in this Github gist. Make sure you download it into the same directory where you have your Dockerfile. cd into the directory where both files live and execute the following:

  • $ docker-compose build: to build the image
  • $ docker-compose up -d: to spin the container
  • $ docker exec -it [CONTAINER NAME] /bin/bash: to be dropped into the container

At this point you should be dropped into the container and you

sgarciav gravatar image sgarciav  ( 2021-06-09 18:38:00 -0600 )edit

This worked for me. Thanks! You don't have to use nvidia. I built a Dockerfile from the ros:kinetic image.

zkytony gravatar image zkytony  ( 2022-01-11 11:00:36 -0600 )edit

answered 2019-05-27 15:29:12 -0600

Marc_Chen gravatar image

I did something similar, but the docker file is much simpler, so it is easier to understand. There is also a video on youtube, hope it helps.

edit flag offensive delete link more


Hi Marc,

I asked a question here

I have tried your solution but it did not work. I am not sure if I am doing it correctly, could you provide some insight?


aarontan gravatar image aarontan  ( 2019-06-24 10:50:55 -0600 )edit


my solution only works when your host machine is windows, in my case I need to install xming, so the signal from the graphic card is redirected to windows instead of ubuntu. So what is the operation system you are using to run the docker? 1. you should try my dockerfile first, make sure that "firefox" works as first step. 2. when firefox works, you know the signal redirection works, then you move on trying your own dockerfile

regards Marc

Marc_Chen gravatar image Marc_Chen  ( 2019-06-25 12:44:13 -0600 )edit

answered 2018-08-09 02:42:58 -0600

bpinaya gravatar image

updated 2018-08-09 03:31:48 -0600

Hey there, I did something related. At the end I used VNC to connect to the docker image and run the gui for Gazebo and Rviz. If you have a decent computer it should run better than with VMs. Check this repo where I detail the install process and the docker image.

At the end it looked like this:

image description

And all of it was running in a docker image. Hope it helps!

(btw there is some extra things you might not need like the workspace I used, that was for a Udacity Assignment)

EDIT: Indeed, for performance you can check the GUI Docker guide from ROS. Connecting to the X11 is the recommended case, especially since you are on Ubuntu 18 already. I did this VNC solution so I can connect from Windows or Mac for example.

edit flag offensive delete link more



Could you please mention that while VNC will work, it is a less performant alternative to the 'regular' approach of exposing X sockets and using the X-server of the host machine?

+1 for mentioning this alternative, but let's not give the impression that this is the recommended way to do this.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-09 03:21:11 -0600 )edit

answered 2021-03-06 08:58:14 -0600

Kansai gravatar image

For Rviz (sorry I haven't been able to do gazebo yet) check this excellent article. Based on this I could manage to use RVIZ on docker

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-08-08 23:32:48 -0600

Seen: 20,111 times

Last updated: Mar 06 '21