Skip to content

Instantly share code, notes, and snippets.

@varunagrawal
Last active June 18, 2020 12:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varunagrawal/29763aa16add0133cd13952f202a7e0e to your computer and use it in GitHub Desktop.
Save varunagrawal/29763aa16add0133cd13952f202a7e0e to your computer and use it in GitHub Desktop.
Docker for ROS
FROM osrf/ros:indigo-desktop-full
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y aptitude
RUN printf 'n\nY\nY\n' | aptitude install ros-indigo-fetch-gazebo-demo
SHELL ["/bin/bash", "-c"]
RUN source /opt/ros/indigo/setup.bash

Getting Started

Build Docker Image

In directory where the Dockerfile is located, run

docker build -t mm8803/fetch:latest .

The image will install everything you need to run the Fetch robot in Gazebo.

Run with X Server

docker run -it \
    --user=$(id -u) \
    --env="DISPLAY" \
    --workdir="/home/$USER" \
    --volume="/home/$USER:/home/$USER" \
    --volume="/etc/group:/etc/group:ro" \
    --volume="/etc/passwd:/etc/passwd:ro" \
    --volume="/etc/shadow:/etc/shadow:ro" \
    --volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    --env QT_X11_NO_MITSHM=1 \
    mm8803/fetch:latest \
    rqt

Enter Container

To open a new terminal in the container, we first need the container ID:

docker ps

Get the container ID that matches the image name we set previously. Let's assume the container ID is 1e275acd4d98 (this was the ID on my machine at the time of writing).

docker exec -it 1e275acd4d98 bash

And you should have a new terminal to run commands in.

Getting Started

Since we exec into a brand new shell, we'll have to source the ROS setup.bash file so that we get access to all the ROS niceness (aka autocomplete).

Just run source /opt/ros/$ROS_DISTRO/setup.bash and you should be good to go.

Acknowledgments

Thanks to Ruffin White (previously at Georgia Tech, now at UCSD) for writing up a great tutorial on using the GUI with docker for ROS.

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