This project provides a ready-to-use Docker container for ROS 1 (ROS Noetic) for development and testing. It simplifies the process of working with ROS in an isolated, reproducible environment that can run on both Windows (via WSL) and Linux. The setup includes GUI support for ROS development in WSLg and native Linux systems, along with easy integration with your existing ROS workspace.
Before you begin, make sure you have the following installed:
- Docker: install Docker for your platform.
- NVIDIA Container Toolkit: install NVIDIA Container Toolkit if you have an NVIDIA GPU.
- Windows Subsystem for Linux (WSL): install WSL if you want to run Docker containers in Windows.
Ensure you have WSLg installed, as it enables GUI support for Docker containers in Windows. If you're unsure about this, refer to the WSLg Installation guide.
If you haven't already, clone this repository to your local machine:
git clone https://github.com/ramsafin/ros-docker.git
cd ros-docker
There are two build options available depending on your environment: WSL and Linux.
Build the Docker image optimized for WSL:
make build_wsl
Build the Docker image optimized for Linux:
make build_linux
The Makefile handles the setup for different environments, adjusting the Dockerfile build arguments accordingly.
To start a container with GUI support and mount your ROS workspace, use:
make run_wsl
or
make run_linux
This will automatically handle display forwarding if you are using WSLg. For non-WSLg setups, you may need to configure access to the X server (e.g., with xhost
in non-WSL2 environments).
By default your ROS workspace inside the container is ROS_WORKSPACE=/home/ros/catkin_ws
.
Once inside the container, navigate to your ROS workspace and build it:
cd $ROS_WORKSPACE && catkin_make
Alternatively, using catkin-tools:
cd $ROS_WORKSPACE && catkin build
This will generate the build/
, devel/
, and install/
directories in the catkin_ws
directory.
If you have uninstalled dependencies, use:
rosdep install --from-paths $ROS_WORKSPACE/src --ignore-src -y
After building your workspace, you can start working with ROS nodes. For example, you can run the ROS master:
roscore
Do not forget to source your ROS environment and workspace:
source /opt/ros/$ROS_DISTRO/setup.bash
source $ROS_WORKSPACE/devel/setup.bash
When you're finished, you can stop the container by typing exit
or pressing Ctrl+D
. Since the container was started with --rm
, it will be automatically removed when stopped.
To manually stop the container, run:
make stop
The NVIDIA GPU can be selected in WSL by setting MESA_D3D12_DEFAULT_ADAPTER_NAME
:
echo "export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA" >> ~/.bashrc
source ~/.bashrc
Follow the instructions in the GPU selection in WSLg guide.
Follow the instructions in the wslg/containers guide.
Ensure that the xhost
command is used to allow Docker to connect to the X server:
xhost +SI:localuser:$(whoami)
Additionally, verify that your X server is running.
Check the output of the command:
glxinfo -B | grep Device
It should be your NVIDIA GPU.
- For more detailed documentation on setting up and using ROS Noetic, visit the official ROS documentation.
- For more information about WSLg, visit the WSLg official repository.
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request. You can also open an issue if you encounter any bugs or have suggestions for improvement.
This project is licensed under the MIT License - see the LICENSE file for details.