Running ROS Inside Docker: A Technical Guide for Unconventional Ubuntu Releases

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:

$ curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
 && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
 sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
 sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
 && \
 sudo apt-get update
 && sudo apt-get install -y nvidia-container-toolkit
 $ sudo nvidia-ctk runtime configure --runtime=docker
 $ sudo systemctl restart docker

For Ubuntu 22.04 Environment:

$ sudo apt install docker.io docker-compose

Verified Version:

$ docker --version
Docker version 24.0.5, build 24.0.5-0ubuntu1~22.04.1
$ docker-compose --version
docker-compose version 1.29.2, build unknown

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:

$ sudo apt-get install ca-certificates curl gnupg
$ sudo install -m 0755 -d /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
$ echo   "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
$ sudo systemctl start docker.service
$ sudo systemctl start docker.socket
$ sudo chmod 666 /var/run/docker.sock
$ alias docker-compose='docker compose'

Verified version:

$ docker --version
Docker version 24.0.7, build afdd53b

$ docker compose version
Docker Compose version v2.21.0

Before Launch:

$ sudo xhost +si:localuser:root

Launch Instances:

$ 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.