How to run ROS inside Docker
Running ROS Inside Docker: A Technical Guide for Unconventional Ubuntu Releases
Introduction:
In this blog post, I share my recent endeavor on running ROS (Robot Operating System) inside Docker, tackling the challenge of using a non-recommended Ubuntu release. ROS, being a “meta OS” for robotics systems, is widely employed in diverse fields like robotics, autonomous vehicles, and drones. The alignment of ROS release cycles with Ubuntu’s LTS releases often presents challenges, especially when dealing with non-standard Ubuntu versions. Docker emerges as a solution to this problem, providing a flexible environment for running ROS with unconventional Ubuntu releases.
The Challenge:
My specific challenge was to run ROS Noetic with Ubuntu 22.04, which is not a recommended combination. Third-party repositories couldn’t easily resolve this issue due to dependencies on specific Ubuntu versions.
The Solution: Dockerized Environment
Diving into the solution, I discovered that a regular Docker image might not suffice for ROS, as it has components demanding a powerful GPU for seamless operation. Consequently, I crafted a Docker image based on nvidia/opengl, ensuring it possesses the capability to access the host’s graphics card. The resulting Docker image is now ready for use.
Hardware and Software Requirements:
To successfully run the ROS Docker image based on nvidia/opengl, certain hardware and software prerequisites must be met:
- The system must be equipped with an Nvidia GPU.
- A proper graphics driver must be installed.
- Nvidia-container-toolkit needs to be installed. The installation steps for Ubuntu 22.04 are outlined below:
1 |
|
For Ubuntu 22.04 Environment:
1 | $ sudo apt install docker.io docker-compose |
Verified Version:
1 | $ sudo apt install docker.io docker-compose |
For Ubuntu 20.04 Environment:
Due to the docker-compose v1 being deprecated, please refer to the official document 1 and 2 to install Docker-Desktop and docker compose plugin packages instead of the candidate docker.io and docker-compose packages from the Ubuntu official repository.
Install instructions:
1 | $ sudo apt-get install ca-certificates curl gnupg |
Verified version:
1 | $ docker --version |
Before Launch:
1 | $ sudo xhost +si:localuser:root |
Launch Instances:
1 | $ docker-compose up |
Conclusion:
By leveraging Docker, particularly with GPU support and thoughtful image creation, running ROS on Ubuntu versions outside the recommended scope becomes a manageable task. This technical guide provides step-by-step instructions for setting up the environment, ensuring a smooth ROS experience even with unconventional Ubuntu releases.