Copy the following files into your project directory:
Dockerfile
to the root of your project; anddevcontainer.json
to.devcontainer/devcontainer.json
in your project.
To allow the container to run GUI applications (e.g., rviz2), you need to run the following command:
# Allow xhost access to local user
xhost +si:localuser:root
In VSCode, install the extension pack Remote Development that allows remote development inside of Docker containers.
Open your project in VSCode, and start remote development by entering Dev Containers: Rebuild and Reopen in Container
into the command palette (CTRL-SHIFT-P
). You can now open a terminal and run your ROS2 nodes:
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
colcon build
source install/setup.bash
ros2 launch launch/launch.py
There might me some error in IntelliSense (e.g., some imports not found), run Python: Clear Cache and Reload Window
in the command palette.