A personal workspace for learning and experimenting with ROS 2 Humble using Docker, GPU acceleration (NVIDIA RTX 4060), and VS Code integration. This README documents setup, installation, and usage so anyone can reproduce the environment.
ROS 2 (Robot Operating System 2) is a flexible framework for writing robot software. It provides:
- A publish/subscribe communication system between nodes
- Tools for simulation (Gazebo, RViz2)
- Libraries for robotics, AI, and machine learning integration
- Support for C++ and Python development
This repository prioritizes a Docker-first approach so you get a reproducible, clean development environment with minimal interference from host packages. That also makes GPU acceleration, VS Code integration, and CI-friendly builds much simpler.
Why Docker?
- Isolates ROS 2 Humble environment from host package manager (Manjaro)
- Easier to enable NVIDIA GPU support via
--gpusandnvidia-container-toolkit - Quick reproducible setup for teammates or future you
- Docker (Recommended) – reproducible, GPU-enabled, minimal host changes.
- AUR packages – quicker to get binaries but can break with rolling releases.
- Source build – most flexible but time-consuming; only recommended for maintainers or for experimental changes to core packages.
These steps assume you have an NVIDIA GPU (RTX 4060) and want GPU acceleration inside the container.
- Install NVIDIA drivers (host) and verify:
nvidia-smi- Install Docker and enable the service:
sudo pacman -Syu docker
sudo systemctl enable --now docker- Install NVIDIA container tooling (on Manjaro):
sudo pacman -S nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker- Test GPU passthrough:
docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smiYou should see your RTX 4060 listed in the container output.
git clone https://github.com/SuhanVerse/Learning-ROS2.git
cd Learning-ROS2If you want a custom image (base: Ubuntu 22.04 + ROS Humble):
# Dockerfile
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
# Install basic dependencies and ROS 2 keys & repos (follow official instructions)
RUN apt-get update && apt-get install -y \
curl gnupg2 lsb-release locales sudo && \
locale-gen en_US.UTF-8
# (Add ROS 2 apt repository & install ros-humble-desktop or ros-humble-ros-base as needed)
# Optional: create a developer user
RUN useradd -m developer && echo "developer:developer" | chpasswd && adduser developer sudo
USER developer
WORKDIR /home/developer
CMD ["/bin/bash"]Tip: Use
ros:humbleorros:humble-ros-baseofficial images for faster iteration when possible.
A minimal docker-compose.yml for development with GPU support:
version: '3.8'
services:
ros2_dev:
image: ros:humble
container_name: ros2_dev
tty: true
privileged: true
network_mode: "host"
environment:
- DISPLAY=${DISPLAY}
- QT_X11_NO_MITSHM=1
volumes:
- $HOME/LEARN:/root/LEARN
- /tmp/.X11-unix:/tmp/.X11-unix:rw
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
runtime: nvidia
command: /bin/bashStart the container:
docker compose up -d --buildAttach to the container shell:
docker exec -it ros2_dev bashInside the container, source ROS 2:
source /opt/ros/humble/setup.bashYou can configure VS Code to open a terminal that drops you into the running container with your workspace sourced. Examples for .vscode/settings.json and .vscode/tasks.json are shown below.
Example: .vscode/settings.json terminal profile
{
"terminal.integrated.profiles.linux": {
"ROS2-Docker": {
"path": "/bin/bash",
"args": [
"-c",
"docker exec -it ros2_dev bash -c '(source /opt/ros/humble/setup.bash && source /root/LEARN/install/setup.bash) || true; exec bash'"
]
}
},
"terminal.integrated.defaultProfile.linux": "ROS2-Docker"
}Example: .vscode/tasks.json snippets for running talker/listener
{
"version": "2.0.0",
"tasks": [
{
"label": "run talker",
"type": "shell",
"command": "docker exec -it ros2_dev bash -c 'source /opt/ros/humble/setup.bash && source /root/LEARN/install/setup.bash && ros2 run demo_nodes_cpp talker'"
},
{
"label": "run listener",
"type": "shell",
"command": "docker exec -it ros2_dev bash -c 'source /opt/ros/humble/setup.bash && source /root/LEARN/install/setup.bash && ros2 run demo_nodes_cpp listener'"
}
]
}Tip: Use the Remote - Containers extension if you prefer VS Code to manage containers for you.
Assuming your ROS 2 workspace is at /root/LEARN inside the container:
cd /root/LEARN
colcon build
source install/setup.bashInstall extra packages if needed:
apt update && apt install -y ros-humble-turtlesimRun the simulator:
# Terminal 1
ros2 run turtlesim turtlesim_node
# Terminal 2
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp listener- Start container:
docker compose up -d - Attach shell:
docker exec -it ros2_dev bash - Source ROS 2 and workspace:
source /opt/ros/humble/setup.bash && source /root/LEARN/install/setup.bash - Build:
colcon build - Run nodes with
ros2 runorros2 launch
- AUR packages – e.g.,
yay -S ros-humble-desktop. Good for native installs but may require maintenance on rolling distributions. - Source build – follow the official ROS 2 instructions to build from source. Useful for bleeding-edge patches or custom core changes.
- GPU not visible in container: ensure
nvidia-container-toolkitis installed anddocker run --gpus all ...works. - Docker permission issues: add your user to the
dockergroup or usesudofor Docker commands. - GUI apps not showing: mount the X11 socket (
/tmp/.X11-unix) and runxhost +local:root(or a more secure alternative). - colcon build failures: verify
package.xmlandCMakeLists.txtfor missing dependencies and userosdepto install OS dependencies.
- ROS 2 official docs: https://docs.ros.org/en/humble/
- Colcon build tool: https://colcon.readthedocs.io/
- NVIDIA Container Toolkit: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/
- ROS 2 tutorials: https://docs.ros.org/en/humble/Tutorials.html
Feel free to open issues or PRs if you have suggestions, updates for newer ROS 2 distributions, or improved Docker setups.
Licensed under the Apache-2.0 License.