Hi there, we got RViz to work through nvidia-docker2 (with OpenGL) by following the guide here:
http://wiki.ros.org/action/login/docker/Tutorials/Hardware%20Acceleration#nvidia-docker2
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.
XAUTH=/tmp/.docker.xauth
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 -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi
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 \
bash
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.
Originally posted by JBruun with karma: 46 on 2020-07-02
This answer was ACCEPTED on the original site
Post score: 3
Original comments
Comment by sgarciav on 2021-06-09:
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
Comment by zkytony on 2022-01-11:
This worked for me. Thanks! You don't have to use nvidia. I built a Dockerfile from the ros:kinetic image.