0

I have a Macbook Pro (M1 Pro chip) with docker-desktop installed.

I also have the following docker file to install ROS2

FROM ubuntu:22.04
RUN apt update

# install python
RUN apt install -y python3

# set locale
RUN apt install -y locales
RUN locale-gen en_US en_US.UTF-8
RUN update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
RUN export LANG=en_US.UTF-8

# add ros2 repository
RUN apt install -y software-properties-common
RUN add-apt-repository universe
RUN apt update
RUN apt install -y curl
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

# disable prompts during installation (ex. Please select the geographic area in which you live)
ENV DEBIAN_FRONTEND = noninteractive

# install common packages
RUN apt update
RUN apt install -y \
    python3-flake8-docstrings \
    python3-pip \
    python3-pytest-cov \
    ros-dev-tools

RUN apt install -y \
    python3-flake8-blind-except \
    python3-flake8-builtins \
    python3-flake8-class-newline \
    python3-flake8-comprehensions \
    python3-flake8-deprecated \
    python3-flake8-import-order \
    python3-flake8-quotes \
    python3-pytest-repeat \
    python3-pytest-rerunfailures

# get ros2 code
# $HOME in this environment is /root. WORKDIR requires absolute paths and therefore, /root is written explicitly in the WORKDIR command (using $HOME doesn't work)
RUN mkdir -p $HOME/ros2_humble/src
WORKDIR /root/ros2_humble
RUN vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src

# install dependencies
RUN apt upgrade
RUN rosdep init
RUN rosdep update
RUN rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

# build code
RUN colcon build --symlink-install

# source environment and add to bashrc
RUN . $HOME/ros2_humble/install/local_setup.bash
RUN echo "source $HOME/ros2_humble/install/local_setup.bash" >> ~/.bashrc

When I build the image and run the container, I can see that ROS2 is working correctly. However with I try to run rviz2, I get the following output:

qt.qpa.xcb: could not connect to display 
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.

Aborted

How can I solve this issue?

I expect that rviz2 windows is normally opened on my MacOS

Hussein Fawzy
  • 366
  • 2
  • 16
  • Docker isn't great for running GUI applications; you need to use the more Unix-oriented X Window System, as in [Can you run GUI applications in a Linux Docker container?](https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-linux-docker-container) (and especially [this answer](/a/51566791)). You might consider whether a virtual machine with a standard simulated display system is a better match for your use case. – David Maze Mar 15 '23 at 14:20
  • Macs don't do X11 GUIs because Apple uses Cocoa. You'd need to install XQuartz to be able to display X11 windows, and run your `docker` like this https://stackoverflow.com/a/75389081/2836621 – Mark Setchell Mar 15 '23 at 15:16

0 Answers0