Skip to content

Instantly share code, notes, and snippets.

@ruffsl
Last active October 12, 2021 09:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ruffsl/e7ca631a618ece3eb0be8e4bf168accb to your computer and use it in GitHub Desktop.
Save ruffsl/e7ca631a618ece3eb0be8e4bf168accb to your computer and use it in GitHub Desktop.
Nvidia docker with rviz
FROM osrf/ros:melodic-desktop-bionic
# setup catkin workspace
ENV CATKIN_WS=/root/catkin_ws
RUN mkdir -p $CATKIN_WS/src
WORKDIR $CATKIN_WS/src
# clone source code
RUN git clone -b melodic-devel https://github.com/ros-visualization/rviz
# install build dependacies
RUN apt-get -qq update && \
apt-get -qq install -y \
python-catkin-tools && \
rosdep update && \
rosdep install -y \
--from-paths . \
--ignore-src \
--rosdistro ${ROS_DISTRO} \
--as-root=apt:false && \
rm -rf /var/lib/apt/lists/*
# build from source
WORKDIR $CATKIN_WS
ENV TERM xterm
ENV PYTHONIOENCODING UTF-8
RUN catkin config \
--extend /opt/ros/$ROS_DISTRO && \
catkin build
# --cmake-args -DCMAKE_BUILD_TYPE=Debug
# setup entrypoint
COPY ./ros_entrypoint.sh /
ENTRYPOINT ["/ros_entrypoint.sh"]
# set environment variables
ENV NVIDIA_VISIBLE_DEVICES ${NVIDIA_VISIBLE_DEVICES:-all}
ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics
all: help
help:
@echo ""
@echo "-- Help Menu"
@echo ""
@echo " 1. make build - build all images"
@echo " 1. make clean - remove all images"
@echo ""
build:
@docker build --tagosrf/ros:melodic-rviz .
clean:
@docker rmi -f osrf/ros:melodic-rviz
#!/bin/bash
set -e
# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"
source "/root/catkin_ws/devel/setup.bash"
exec "$@"
#!/usr/bin/env bash
# Runs a docker container with the image created by build_demo.bash
# Requires
# docker
# nvidia-docker2
# an X server
# Make sure processes in the container can connect to the x server
# Necessary so gazebo can create a context for OpenGL rendering (even headless)
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
if [ ! -z "$xauth_list" ]
then
echo $xauth_list | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi
docker run -it --rm \
--runtime=nvidia \
--env DISPLAY \
--env QT_X11_NO_MITSHM=1 \
--env XAUTHORITY=$XAUTH \
--volume "$XAUTH:$XAUTH" \
--volume "/tmp/.X11-unix:/tmp/.X11-unix" \
osrf/ros:melodic-rviz \
bash -c "roscore & rviz"
@hany606
Copy link

hany606 commented Oct 12, 2021

Only a small mistake in Makefile (no space between --tag and the following part), it should be as following:

all: help

help:
	@echo ""
	@echo "-- Help Menu"
	@echo ""
	@echo "   1. make build            - build all images"
	@echo "   1. make clean            - remove all images"
	@echo ""

build:
	@docker build --tag osrf/ros:melodic-rviz .

clean:
	@docker rmi -f osrf/ros:melodic-rviz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment