본문 바로가기
카테고리 없음

Docker를 통한 ROS2 Humble 설치

by Z0e 2025. 3. 12.

 

 

 

 

 

ROS 2 in Docker

 

 

 

관련 포스팅

 

 

 

 

ROS distro

Ubuntu 버전에 따라 사용할 수 있는 ROS distro가 다르다.

Ubuntu 22.04 ROS 2 Humble Hawksbill
Ubuntu 24.04 ROS 2 Jazzy Jalisco

 

 

ROS 배포 비율

2025년 1월 1일 기준 Humble은 48% 비율을 갖고 있고, 그만큼 안정적이다.

ROS Distro
https://metrics.ros.org/packages_rosdistro.html

 

 

 

ROS 2 Humble을 Docker로 설치하려는 이유

나의 경우 Ubuntu 24.04가 설치되어있고, 다른 배포판에 비해 안정적인 ROS 2 Humble을 사용하고자 하기에 docker로 설치하려고 한다.

 

 

 

Docker를 통한 ROS 2 Humble 설치

 

Running ROS 2 nodes in Docker [community-contributed] — ROS 2 Documentation: Humble documentation

You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Jazzy.

docs.ros.org

 

 

이미지 다운로드

Gazebo, RViz와 같은 개발 도구를 포함한 Full desktop ROS 2 image를 다운로드 받는다.

docker pull osrf/ros:humble-desktop-full
명령어 문제 발생 시, `sudo`로 실행하거나 docker 그룹을 통해 권한 문제 해결 (참고)

 

 

컨테이너 실행

docker run \
    --name <Container_name> \
    -it \
    --privileged \
    -e DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    -v <Host_ws>:<Container_ws> \
    -w <Work_dir> \
    osrf/ros:humble-desktop-full
docker run \
    --name ros2-humble \
    -it \
    --privileged \
    -e DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    -v $HOME/project/ros_ws:/root/ros_ws \
    -w /root/ros_ws \
    osrf/ros:humble-desktop-full

 

옵션 설명

`--name` : 컨테이너 이름 지정

`--restart always` : 컨테이너가 stop되면 항상 재시작 

`-it` : 터미널 명령 사용 (interaction)

`--privileged` : 주요 자원 접근 옵션 

`-e DISPLAY=$DISPLAY` : `DISPLAY` 환경 변수를 host에서 컨테이너로 전달하여 host에서 GUI 출력

`-v [호스트 경로]:[컨테이너 경로]` : 컨테이너에 host의 디렉토리 연결

`-v /tmp/.X11-unix:/tmp/.X11-unix:rw` : 컨테이너가 host의 GUI 환경(X server)을 사용할 수 있도록 함. `:rw` read/write

`-v $HOME/project/ros_ws:/root/ros_ws` : 컨테이너의 root/ros_ws 폴더와 host의 ~/project/ros_ws가 연결되도록 함

`-w [시작 경로]` : 컨테이너 진입 시 시작 경로

항상 컨테이너가 재시작하길 원하면 `-d --restart always` 옵션을 추가한다.

 

 

RViz 2 실행

rivz2

RViz

 

 

컨테이너 접속 해제

exit

 

 

 

컨테이너 상태 확인

docker ps -a

STATUS가 Exited 라면 중지된 상태

 

 

컨테이너 재실행

docker start <컨테이너 이름>
docker start ros2-humble

 

재부팅 될 때마다 재시작하도록 하려면

docker update --restart=always <container>

 

 

 

실행중인 컨테이너 접속

docker exec -it ros2-humble /bin/bash

 

zsh-in-docker 설치 이후

docker exec -it ros2-humble /bin/zsh

 

 

 

ROS 환경 설정

의존성 패키지 설치

apt-get update && apt-get install -y \
    build-essential \
    cmake \
    curl \
    gazebo \
    git \
    libbullet-dev \
    libglu1-mesa-dev \
    nano \
    neovim \
    python3-flake8 \
    python3-pip \
    python3-pydantic \
    python3-pytest-cov \
    python3-rosdep \
    python3-setuptools \
    python3-vcstool \
    ros-humble-gazebo-ros \
    ros-humble-gazebo-ros-pkgs \
    ros-humble-joint-state-publisher \
    ros-humble-joint-state-publisher-gui \
    ros-humble-robot-localization \
    ros-humble-plotjuggler-ros \
    ros-humble-robot-state-publisher \
    ros-humble-ros2bag \
    ros-humble-rosbag2-storage-default-plugins \
    ros-humble-ros-core \
    ros-humble-geometry2 \
    ros-humble-rqt-tf-tree \
    ros-humble-rmw-fastrtps-cpp \
    ros-humble-rmw-cyclonedds-cpp \
    ros-humble-slam-toolbox \
    ros-humble-turtlebot3 \
    ros-humble-turtlebot3-msgs \
    ros-humble-twist-mux \
    ros-humble-usb-cam \
    ros-humble-urdf-tutorial \
    ros-humble-xacro \
    ruby-dev \
    rviz \
    tmux \
    wget \
    xorg-dev \
    zsh
pip3 install setuptools==58.2.0

 

 

ZSH 설치

 

GitHub - deluan/zsh-in-docker: Install Zsh, Oh My Zsh and plugins inside a Docker container with one line!

Install Zsh, Oh My Zsh and plugins inside a Docker container with one line! - deluan/zsh-in-docker

github.com

sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.2.1/zsh-in-docker.sh)" -- \
   -p git \
   -p https://github.com/zsh-users/zsh-autosuggestions \
   -p https://github.com/zsh-users/zsh-completions \
   -p https://github.com/zsh-users/zsh-syntax-highlighting

 

 

shell startup script 설정

echo "export DISABLE_AUTO_TITLE=true" >> ~/.zshrc
echo 'LC_NUMERIC="en_US.UTF-8"' >> ~/.zshrc
echo "source /opt/ros/humble/setup.zsh" >> ~/.zshrc
echo "source /usr/share/gazebo/setup.sh" >> ~/.zshrc
source ~/.zshrc

 

환경변수 확인

printenv | grep -i ROS

 

 

Python 설치

curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
source ~/.zshrc
pyenv install 3.8 3.10
pyenv global 3.10

 

패키지 설치

pip3 install rospkg catkin_pkg
pip3 install scikit-build
pip3 install cmake
pip3 install opencv-python
pip3 install cvbridge3

 

 

 

ROS Demo

talker

docker exec -it ros2-humble /bin/zsh
ros2 run demo_nodes_cpp talker

listener

docker exec -it ros2-humble /bin/zsh
ros2 run demo_nodes_cpp listener

 

 

 

Troubleshooting

ROS 2에서 GUI가 제대로 동작하지 않을 때

qt.qpa.xcb: could not connect to display :1
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

 

host에서 아래 명령어를 통해 도커가 XServer와 통신할 수 있도록 한다

xhost +local:docker

 

 

 

CV2 관련 오류

pip uninstall opencv-python
pip install opencv-python-headless

 

 

 

 

 

참고

 

ROS2 in Docker — Why and How?

In this article, I will discuss why integrating ROS2 into Docker is desirable and how we can do that with a few simple commands. If you’re…

medium.com

 

GitHub - sskorol/ros2-humble-docker-dev-template: This repo provides a template for a quick start with a ROS2 Humble development

This repo provides a template for a quick start with a ROS2 Humble development in Docker - sskorol/ros2-humble-docker-dev-template

github.com

 

solved: Could not load the Qt platform plugin "xcb" · NVlabs instant-ngp · Discussion #300

I will leave here solution for a problem that I could not fix for days, hope it would help someone: So, the error was: QObject::moveToThread: Current thread (...) is not the object's thread (...). ...

github.com