TL;DR - Dev Containers ROS 2 is a repository that contains ready-to-use environment that lets you work across different ROS 2 installations / distributions. You should try it out!
Many ROS 2 packages are released across different ROS 2 distributions, and docker seems to currently be the most popular way of developing and testing. As a package maintainer, you often have to switch between distros (that target different platforms), to investigate bugs and fix them.
I maintain a couple of packages across different ROS 2 distributions, and so far, I’ve really liked using VS Code Devcontainers with ROS 2 Docker Images. However, these docker containers include the very minimum, and isn’t enough to set up a ROS 2 development environment similar to native development.
Dev Containers ROS 2 is a repository that I initially wrote just for myself to make maintaining packages across different distritbuions easier, but I’ve started to feel that its useful for others, so I’ve brushed it up and made it available.
It has dev containers for:
Foxy (core, base, desktop)
Galactic (core, base, desktop)
Humble (core, base, desktop, desktop-full)
Rolling (core, base, desktop, desktop-full)
It has settings included that enables:
Can open GUI applications
apt dependencies are up-to-date
can clone a repository with git clone git@github.com:/... (openssh-client is installed)
gdb is installed
source /opt/ros/${ROS_DISTRO}/setup.bash already added to ~/.bashrc
Uses the host network interface (so can communicate across your network)
Can access your webcam
Please give it a try! I’m interested to hear ways to go about improving it too.
Also, here is a great article about using ROS 2 with dev containers by Allison Thackston - VSCode, Docker, and ROS2.
This is awesome! I use a very similar set up. Have you considered directly adding extensions to the devcontainer.json? Maybe some basic ones like python, c++, and maybe even the ros extension.
VS Code Dev Containers lets you install your locally installed Extensions into your docker container through one-click. I’ve added instructions in the README on how to do this.
I believe that is better than me selecting a handful of extensions to have pre-installed
Hello! Just to quickly mention that this does not work anymore. The base image already creates a user called “ubuntu” with UID and GID set to 1000; so when the Dockerfile tries to create one, it fails the build. I have spent a painful afternoon figuring this out, but the lines
Indeed, I think this was a change introduced in the Ubuntu 23.04 docker images:
For my use case, I’ve opted to reuse the ubuntu user, as the devcontainer CLI automatically remaps the GID to be the same as the host user at runtime, so no need to bake that into the image.
You can add something like this to remove any user with same gid if present.
# Check if any user already exist with same GID and if exist delete it
RUN awk -v gid="${USER_GID}" -F':' '$4 == gid {print $1}' /etc/passwd | xargs -r userdel -r
Thanks for bringing this up. it sounds like you are using the ROS dev container templates (which i am also the author of). I’m going to assume you are using the dev container templates, and not the dev_container_ros2 repo from this original post.
I have updated the ros dev container templates today to fix this . Try and re-add a dev container configuration to your workspace, and you can expect the jazzy and rolling dev containers generated from the template to get built correctly. I have updated the dockerfile such that the jazzy / rolling templates will re-use the ubuntu user from the base image, instead of creating a new user.
If it works, i appreciate if you could leave a reaction on this post so I know it’s working. If it’s not working, please leave a comment!