ROS development environment
This repo contains a set of configuration files to generate docker images for development in ROS. The aim of this project is to provide a development environment that can be used in any ROS distribution. It's not intended to be used for production purposes, only development purposes, therefore some useful configurations are considered, e.g. sharing your home directory with the container.
Prerequisites
A good starting point is to follow the good practices from health robotics group and install the required packages: docker, rocker, rocker extensions, and nvidia-container-toolkit.
Summary
Docker
# First, uninstall old docker versions
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Then, install latest version of docker using apt
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Install docker
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Create the docker group.
sudo groupadd docker
# Add your user to the docker group.
sudo usermod -aG docker $USER
# Refresh permissions to docker group.
newgrp docker
Rocker and Rocker extensions
# if pipx is not installed
# for 22.04 or below
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# The installation of rocker is then reduced to:
pipx install git+https://github.com/osrf/rocker.git
pipx inject rocker git+https://github.com/sloretz/off-your-rocker.git
pipx inject rocker git+https://github.com/miguelprada/mp_rocker.git
pipx inject rocker git+https://github.com/anfemosa/roscker_extensions.git # WIP
Nvidia-container-toolkit
# Configure production repositories
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Install nvidia-container-toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
Install Development Environment
Clone the repository:
git clone git@git.code.tecnalia.com:andres.montano/development_environment.git
How to use it
Before generate a docker image
The dockerfile allows the installation of package dependencies for the workspace these could be ROS packages or python packages, installed with apt-get or pip. Packages are defined in a requirements.txt file at ws_dependencies folder, the file name is defined by the ROS_DISTRO (e.g. ./ws_dependencies/melodic_requirements.txt).
noetic_requeriments.txt file example:
# APT-GET PACKAGES
# Base
python3-catkin-tools
ipython3
python-is-python3
python3-click
python3-numpy
python3-osrf-pycommon
python3-vcstool
python3-pip
clangd
liblldb-dev
libllvm-ocaml-dev
# Neurondones
ros-noetic-libpcan
ros-noetic-moveit-ros-move-group
ros-noetic-moveit-fake-controller-manager
ros-noetic-moveit-kinematics
ros-noetic-moveit-planners-ompl
ros-noetic-moveit-ros-visualization
ros-noetic-moveit-setup-assistant
ros-noetic-ros-control
ros-noetic-ros-controllers
# PIP PACKAGES
pyk4a
# EOF
TIP To obtain the dependencies list for you workspace you can use the command rosdep check --from-paths src --ignore-src
or rosdep install --reinstall --simulate --from-path src --ignore-src --skip-keys --rosdistro ${ROS_DISTRO}
If some extra libs are needed, they can be added in extra_libs folder, where a common_libs.txt file is located jointly with ROS_DISTRO_libs.txt files. These libs are packages downloaded and installed in the docker image during the build process. Therefore, files containing urls with links to the sources of the libs.
Example of common_libs.txt file:
# List with links to additional libraries to install in devenv image
# lsd-musl
https://github.com/lsd-rs/lsd/releases/download/v1.1.5/lsd-musl_1.1.5_amd64.deb
The package dependencies as binaries can be passed to the dockerfile with the option --build-arg PACKAGES=${ws_packages}
e.g. docker build --build-arg PACKAGES=neurondones_humble -t deven:humble .
TECNALIA login info (Deprecated?)
An auth.conf file with TECNALIA login info is required to add access to the Tecnalia's artifactory repository.
machine https://artifact.tecnalia.com/artifactory/tecnalia-robotics-debian
login USER@tecnalia.com
password AVERYLONGPASSWORDGENERATEDBYTOKENINARTIFACTORY
dotfiles
There are a bunch of useful optional functions to simplify the docker or ros usage at dotfiles. Check repo readme to get more info.
Summary
echo "${BLUE} dockbuild: Build a docker image for ROS"
echo "Usage: dockbuild <ROS_DISTRO> [build_args]"
echo "ROS_DISTRO: Ros distribution. e.g. melodic, noetic, humble, etc."
echo "build_args:"
echo " --shell: shell to use in the container. e.g. bash or zsh"
echo " --ws: file name with packages to install in the workspace. e.g. neurondones_humble.txt"
echo " --force: force rebuild the image"
echo "Whiout build_args, default shell: ${ext}${NC}"
echo "${BLUE} dockrun: Run a docker image for ROS"
echo "Usage: dockrun <ROS_DISTRO> [options]"
echo "ROS_DISTRO:"
echo " melodic, noetic, humble, jazzy,etc."
echo "Options:"
echo " --ws: path to workspace. e.g. odin_ws"
echo " --share: resource to share with the container, e.g. video, pcan or dev"
echo " --shell: shell to use in the container. By default zsh"
echo " --parse: parse_args to use in the container, e.g. --oyr-spacenav. By default none"
echo " --image: use an specific image. By default uses the ROS base image"
echo "Examples:"
echo "dockrun humble --ws mairon_ws"
echo "dockrun noetic --ws neurondones_ws --share pcan"
echo "dockrun melodic --ws odinrobot_ws --share video --shell bash${NC}"
Summary
There are four configuration files:
- distro_dependencies -- common to all workspaces at the same ros distro
- ws_dependencies -- particular dependencies for a given workspace
- extra_libs -- deb packages to install in the docker image
- auth.conf -- TECNALIA's artifactory login info
To build a docker image:
docker build -t devenv:${ros_distro} ${build_options} -f devenv.Dockerfile .
e.g.
docker build -t devenv:humble --build-arg ROS_DISTRO=${ros_distro} --build-arg PACKAGES=dummy_humble.txt -f devenv.Dockerfile .
or
dockbuild humble --shell zsh --ws neurondones_humble --force
where build_options could be:
--build-arg ROS_DISTRO=${ros_distro} # Mandatory
--build-arg PACKAGES=${ws_packages}
--build-arg SHELL=${ext}
--build-arg SHELL=${shell_path}
--no-cache
To run a container:
rocker --home --ssh --git --user --user-preserve-groups --privileged --nvidia --x11 --network host --name ${container_name} ${image} zsh
or
dockrun melodic --ws odinrobot_ws --share dev
ROS and VS-Code
To use ROS with VS Code there a lot of resources but most of them are focused on launch a docker image and then attach VS-Code to it. The problem with this approach is it does not allow to properly debug ROS nodes in VS-Code.
Resources list:
- Setup ROS 2 with VSCode and Docker
- ROS 2 and VSCode
- VSCode ROS2 Workspace Template
- Step By Step Integration of ROS in VS Code
- IDE Visual Studio Code
- IDEs and Debugging
One of the most complete guide is Setup ROS 2 with VSCode and Docker, it is a good starting point and it is maintained by the ROS Community.
To summarize, some configuration files should be added to workspace: '.devconatiner' folder including 'devcontainer.json' and 'Dockerfile', '.vscode' folder including 'launch.json' and 'tasks.json' files.
- devcontainer.json contains the configuration to launch the container on VS-Code. Including Mount points, VS-Code extensions and Shared resources.
- Dockerfile contains the configuration to add $USER to the container avoiding permission issues.
- launch.json contains the configuration to launch a ROS node in the container.
- tasks.json contains the configuration to define tasks in VS-Code.
- on .vscode folder, other config files appear: c_cpp_properties.json and settings.json, which are autogenerated by VS-Code, but could be modified by the user.
Examples of functional commented files are stored at vscode_config folder.
As final remarks, the launch.json and tasks.json should be adapted to workspace/project needs. The launch.json
contains the configuration to launch a ROS node in the container, it is recommended to avoid debug nodes like RViz or Gazebo (GZ), therefore the launch file should only be used to launch core project nodes.
In order to make easy to use the configurations, a local env could be loaded with direnv (.envrc file), but it is not mandatory.
Contributors
Feedback
If you have any feedback or suggestions about this project, please reach out to me by teams at or open an issue at the project repository.