Skip to content

Instantly share code, notes, and snippets.

@audrow
Last active April 11, 2024 05:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save audrow/259aa7f8ccf446c9b47d74aefe67df7b to your computer and use it in GitHub Desktop.
Save audrow/259aa7f8ccf446c9b47d74aefe67df7b to your computer and use it in GitHub Desktop.
My ROS 2 and Gazebo Docker Setup

README

My ROS 2 and Gazebo Docker setup. This can be extended or used an example for other Docker containers that want to use graphics and have persistent volumes.

Features

  • Run Gazebo and ROS 2 in a Docker container
  • Persistent workspace
  • Graphics support
  • Share your config files, such as you ~/.vimrc

Setup

  1. Install Docker, Rocker, and Off-Your-Rocker (from this PR, if it hasn't already been merged in)
  2. Clone this gist and enter the directory
  3. Build an image with the docker file:
    docker image build --tag ros2-gazebo .
    
  4. Create a Docker volume:
    docker volume create ros2-gazebo
    
  5. Run the rocker run script:
    bash rocker_run.bash
    
FROM ubuntu:focal
ENV WS /root/dev
ENV ROS_PATH $WS/ros2_ws
ENV GAZEBO_PATH $WS/gazebo
ENV ROS_DISTRIBUTION rolling
ENV DEBIAN_FRONTEND noninteractive
# Install essentials
RUN \
apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
apt-utils \
software-properties-common \
&& apt-get update \
&& apt-get install -y \
curl \
gdb \
git-gui \
meld \
mesa-utils \
mpg123 \
nautilus \
libgl1-mesa-glx \
libgl1-mesa-dri \
stress \
stress-ng \
terminator \
tmux \
unzip \
vim \
vlc \
wget \
&& sed -i 's/geteuid/getppid/' /usr/bin/vlc \
&& rm -rf /var/lib/apt/lists/*
# Setup rr, C++ reversable debugging
RUN \
apt-get update \
&& apt-get install -y \
capnproto \
ccache \
cmake \
coreutils \
g++-multilib \
libcapnp-dev \
make \
manpages-dev \
ninja-build \
pkg-config \
python3-pexpect \
&& git clone https://github.com/mozilla/rr.git \
&& mkdir obj \
&& cd obj \
&& cmake ../rr \
&& make -j8 \
&& make install \
&& rm -rf /var/lib/apt/lists/*
# Add github command line
RUN \
apt-get update \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 \
&& apt-add-repository https://cli.github.com/packages \
&& apt-get update \
&& apt-get install -y \
gh \
&& rm -rf /var/lib/apt/lists/*
# Setup Pycharm
ARG PYCHARM_VERSION=pycharm-community-2020.3.3
RUN \
wget https://download.jetbrains.com/python/${PYCHARM_VERSION}.tar.gz \
&& mv pycharm-community-* pycharm-community.tar.gz \
&& tar xfz pycharm-*.tar.gz -C /opt/ \
&& rm pycharm-community.tar.gz \
&& echo "alias pycharm=\"/opt/${PYCHARM_VERSION}/bin/pycharm.sh\"" >> /root/.bashrc
# Setup ROS2 Rolling from source as per
# https://index.ros.org/doc/ros2/Installation/Rolling/Linux-Development-Setup/
RUN \
# setup locale
apt-get update && apt-get install locales \
&& locale-gen en_US en_US.UTF-8 \
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
&& export LANG=en_US.UTF-8 \
# install development tools and ros tools
&& apt-get update && apt-get install -y curl gnupg2 lsb-release \
&& curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - \
&& sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list' \
&& apt-get update \
&& apt-get install -y \
build-essential \
cmake \
git \
libbullet-dev \
python3-colcon-common-extensions \
python3-flake8 \
python3-pip \
python3-pytest-cov \
python3-rosdep \
python3-setuptools \
python3-vcstool \
wget \
# install some pip packages needed for testing
&& apt-get update \
&& python3 -m pip install \
argcomplete \
flake8-blind-except \
flake8-builtins \
flake8-class-newline \
flake8-comprehensions \
flake8-deprecated \
flake8-docstrings \
flake8-import-order \
flake8-quotes \
pytest-repeat \
pytest-rerunfailures \
pytest \
setuptools \
# install Fast-RTPS dependencies
&& apt-get install --no-install-recommends -y \
libasio-dev \
libtinyxml2-dev \
# install Cyclone DDS dependencies
&& apt-get install --no-install-recommends -y \
libcunit1-dev \
# setup the workspace
&& mkdir -p $ROS_PATH/src \
&& cd $ROS_PATH \
&& wget https://raw.githubusercontent.com/ros2/ros2/master/ros2.repos \
&& vcs import src < ros2.repos \
# install package dependencies
&& rosdep init \
&& rosdep update \
&& rosdep install --from-paths src --ignore-src --rosdistro rolling -y --skip-keys "console_bridge fastcdr fastrtps rti-connext-dds-5.3.1 urdfdom_headers" \
# setup bloom for making releases
&& apt-get install -y \
python3-catkin-pkg \
python3-bloom \
&& rm -rf /var/lib/apt/lists/*
# Build the ROS2 workspace
RUN \
cd $ROS_PATH \
&& colcon build --symlink-install
# Setup gazebo
ENV GAZEBO_MAJOR_VERSION 11
COPY ./setup_gazebo.bash /setup_gazebo.bash
RUN \
bash /setup_gazebo.bash \
&& rm -rf /var/lib/apt/lists/*
RUN \
git clone https://github.com/osrf/gazebo $GAZEBO_PATH \
&& mkdir $GAZEBO_PATH/build \
&& cd $GAZEBO_PATH/build \
&& cmake .. \
&& make -j4 \
&& make install
# Personal preferences
RUN \
echo " \
skip -gfi /usr/include/c++/*/*\n\
skip -gfi /usr/include/c++/*/*/*.h\n\
" >> ~/.gdbinit \
&& echo " \
sysctl kernel.perf_event_paranoid=1 > /dev/null\n\
source $ROS_PATH/install/setup.bash\n\
source /usr/share/vcstool-completion/vcs.bash\n\
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash\n\
alias gb='git branch -a'\n\
alias gcb='git checkout -b'\n\
alias gd='git diff HEAD'\n\
alias gg='git gui'\n\
alias gl='git log --pretty=oneline --graph'\n\
alias gs='git status'\n\
alias rh='cd $ROS_PATH'\n\
alias cdrr='cd /root/.local/share/rr/'\n\
alias cb='rh; colcon build --symlink-install'\n\
alias cbd='cb --cmake-args -DCMAKE_BUILD_TYPE=Debug'\n\
alias cbs='cb --packages-select'\n\
alias cbds='cbd --packages-select'\n\
alias cbu='cb --packages-up-to'\n\
alias cbdu='cbd --packages-up-to'\n\
alias code='code --user-data-dir /root/.visual_code/'\n\
alias ct='colcon test'\n\
alias ctl='ct --mixin linters-only'\n\
alias cts='ct --packages-select'\n\
alias ctls='ctl --packages-select'\n\
alias ctr='colcon test-result --verbose'\n\
alias ctra='colcon test-result --verbose --all'\n\
alias ctrd='colcon test-result --delete'\n\
alias gdb1='gdb --eval-command run --batch'\n\
alias vcscheckout='vcs custom --git --args checkout'\n\
alias STRESS='stress -c $(nproc) -m $(nproc) -i $(nproc) -d $(nproc)'\n\
function repeat { while \$1; do \$2:; done; }\n\
function repeatg { while gdb1 \$1; do \$2:; done; }\n\
function cbts { cbs $1 && cts $1 && ctr; }\n\
function update_ros2 { \n\
rh\n\
rm ros2.repos\n\
wget https://raw.githubusercontent.com/ros2/ros2/master/ros2.repos\n\
vcs custom --args remote update\n\
vcs import src < ros2.repos\n\
vcs pull src\n\
cb\n\
}\n\
bash -c 'echo /root/core_dumps/core.%e.%t > /proc/sys/kernel/core_pattern'\n\
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$ROS_PATH/build/test_rclcpp\n\
" >> ~/.bashrc
#!/bin/bash
rocker --nvidia --x11 \
--oyr-mount \
ros2-gazebo:/root/dev \
~/.vimrc:/root/.vimrc:ro \
~/.vim:/root/.vim:ro \
~/.config:/root/.config:ro \
-- \
ros2-gazebo bash
source $ROS_PATH/install/setup.bash
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update
wget https://raw.githubusercontent.com/ignition-tooling/release-tools/master/jenkins-scripts/lib/dependencies_archive.sh -O /tmp/dependencies.sh
GAZEBO_MAJOR_VERSION=11 ROS_DISTRO=rolling . /tmp/dependencies.sh
echo $BASE_DEPENDENCIES $GAZEBO_BASE_DEPENDENCIES | tr -d '\\' | xargs sudo apt-get -y install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment