๐ก ๋ณธ ๋ฌธ์๋ '[Linux] X11 ํฌ์๋ฉํ๊ธฐ (Ubuntu, MacOS XQuartz): ์๋ฒ/๋์ปค์์ QUI ํ์ธํ๊ธฐ)'์ ๋ํด ์ ๋ฆฌํด๋์ ๊ธ์ ๋๋ค.
Ubuntu ์๋ฒ๋ docker ์ปจํ ์ด๋์์ GUI ํ๋ก๊ทธ๋จ์ ์คํ์ํฌ ๊ฒฝ์ฐ, X11 forwarding์ ํตํด ํด๋น host์์ ๋์ธ ์ ์๋๋ก ์ค์ ํด์ฃผ๋ ๊ณผ์ ์ด ํ์ํ๋ฐ ํด๋น ๋ด์ฉ์ ๋ํด ์ ๋ฆฌํ์์ผ๋ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.
1. X11 ํฌ์๋ฉ
1.1. X11 ํฌ์๋ฉ์ด๋?
๋ณ๋๋ก ์๋ ๋ฆฌ๋ ์ค PC์ ssh ์ ์์ผ๋ก ์ฝ์ ์์ ์ ๊ฐ๋ฅํ๋ฐ GUI ํ๋ก๊ทธ๋จ์ ์คํ ํ ์๊ฐ ์์ต๋๋ค. ์ด๋ GUI ํ๋ฉด์ ํฌ์๋ฉํด์ ๋งฅ์์ ๊ทธ ํ๋ฉด๊ณผ ์กฐ์์ ๊ฐ๋ฅํ๊ฒ ํ ๋ ค๋ฉด X11 ํฌ์๋ฉ์ ํ๋ฉด ๋ฉ๋๋ค.
์ ๋ ๋ฉ์ธ์ผ๋ก macOS๋ฅผ ์ฌ์ฉํด์ macOS์์ ์ฌ์ฉ ํ ์ ์๋ ๋ฐฉ๋ฒ์ ์์ ๋ณด๊ฒ ์ต๋๋ค . ์๋ ๋งํฌ๋ฅผ ์ฐธ์กฐ ํ์์ผ๋ฉฐ ์๋ ๋งํฌ์์๋ macOS ๋ฟ๋ง์ด ์๋๊ณ ์๋์ฐ์ ๋ฆฌ๋ ์ค์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๋ ์์ผ๋ ์ฐธ๊ณ ํ์๋ฉด ๋ฉ๋๋ค.
- [blog] How to Set Up and Use X11 Forwarding on Linux and Mac: https://www.businessnewsdaily.com/11035-how-to-use-x11-forwarding.html
1.2. X11 ํ๊ฒฝ ์ค์
X11 ํ๊ฒฝ ์ค์ (in Window)
VcXsrv Windows X Server Download: https://sourceforge.net/projects/vcxsrv/files/latest/download
X11 ํ๊ฒฝ ์ค์ (in Ubuntu)
$ sudo apt-get update
$ sudo apt-get -y install xorg xrdp xserver-xorg mesa-utils xauth gdm3
$ xhost +local:root
X11 ํ๊ฒฝ ์ค์ (in MacOS)
macOS์์๋ XQuartz๋ผ๋ ํ๋ก๊ทธ๋จ์ ์ค์นํ๋ฉด ๋ฉ๋๋ค. ํ๋ก๊ทธ๋จ ํํ์ด์ง์์ ์ค์น ํ์ผ์ ๋ค์ด๋ก๋ ํ ์๋ ์์ง๋ง brew๋ฅผ ํตํด์๋ ์ค์น๋ฅผ ํ ์ ์์ต๋๋ค.
% brew install --cask xquartz
๋ค์ ๋ก๊ทธ์ธํ๊ฑฐ๋ ์ฌ๋ถํ ํ๋ฉด Mac์์ ๊ธฐ๋ณธ X11 server๋ก XQuartx๊ฐ ํ์ฑํ๋์ด X11 ํฌ์๋ฉ์ด ๊ฐ๋ฅํฉ๋๋ค. ์ดํ XQuartz์ ์ค์ ์ ์ด์ด Security(๋ณด์) ํญ์์ "Allow connections from network clients(๋คํธ์ํฌ ํด๋ผ์ด์ธํธ์์์ ์ฐ๊ฒฐ์ ํ์ฉ)"๋ฅผ ํด๋ฆญํ์ฌ ํด๋ผ์ด์ธํธ ์ ์์ด ๊ฐ๋ฅํ๋๋ก ํฉ๋๋ค.

์ถ๊ฐ๋ก xhost ์ค์ ์ ํด์ฃผ๋ฉด ๊ธฐ๋ณธ์ ์ธ ์ค์ ์ด ๋๋ฉ๋๋ค.
% nano ~/.bashrc
...
xhost + <Server IP>
% source ~/.bashrc
2. X11 ํฌ์๋ฉ
2.1. ubuntu ์๋ฒ ์ ์
2.1.1. Shell ์คํฌ๋ฆฝํธ ํ์ฉ
ssh๋ก ์ ์์ -X ์ต์ ์ ์ฃผ๋ฉด X11 ํฌ์๋ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
% ssh -X sjchoi@192.168.0.1
์ดํ x11-apps์ ๋ด์ฅ๋์ด ์๋ GUI ํ๋ก๊ทธ๋จ(xeyes)์ ์คํํด ๋ณด๋ฉด ์ ์์ ์ผ๋ก ํ์๊ฐ ๋ฉ๋๋ค.
sjchoi@sjchoi-desktop$ xeyes
โ2.1.2. VSCode ํ์ฉ
vscode extension์์ 'Remote-SSH'๋ฅผ ์ค์นํ์ฌ vscode์์ ์๊ฒฉ์ผ๋ก ์์ ํ ์ ์๋๋ก ๋ง๋ญ๋๋ค.

ssh ์ค์ ๊ด๋ฆฌํ๋ ํ์ผ์ธ ~/.ssh/config ๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ForwardX11, ForwardX11Trusted๋ฅผ yes๋ก ์ถ๊ฐํฉ๋๋ค.
Host 192.168.0.1
HostName 192.168.0.1
User sjchoi
ForwardX11 yes
ForwardX11Trusted yes
2.2. docker ์ปจํ ์ด๋ ์ ์
2.2.1. docker-compose.yml ํ์ฉ
์ฐธ๊ณ : https://github.com/DrawingProcess/ros2-gazebo-docker-arm64
version: "3.8"
services:
ros2:
build:
context: docker/ros2
args:
- user_id=1000
- ros_ws=/home/dockeruser/dev_ws
# Enabling GPU access with Compose
# https://docs.docker.com/compose/gpu-support/
# deploy:
# resources:
# reservations:
# devices:
# - capabilities: [gpu]
# count: all
environment:
# Set a fancy prompt (See ~/.bashrc in the container)
- TERM=xterm-256color
# Mac X11
- DISPLAY=192.168.35.143:0
volumes:
- ./:/home/dockeruser/project
- ./dev_ws:/home/dockeruser/dev_ws
- ./docker/ros2/.ros:/home/dockeruser/.ros
- ./docker/ros2/.gazebo/:/home/dockeruser/.gazebo
# Mac X11
- /tmp/.X11-unix:/tmp/.X11-unix
- ~/.Xauthority:/root/.Xauthority:rw
privileged: true
์ฌ๊ธฐ์ ์ค์ํ ๊ฒ์ DISPLAY ํ๊ฒฝ๋ณ์ ์ค์ ์ ์์ด์ ํ๋ฉด์ ๋์ฐ๊ณ ์ ํ๋ '<Host OS IP>:0'์ ๋ฃ์ด์ฃผ์ด์ผ ํ๋ค๋ ์ ์ด๋ฉฐ, host์ ๊ฒฝ์ฐ ์์์ ์ธ๊ธํ xhost + <Server IP>๋ก ํน์ ์๋ฒ์ ๋ํ ์ ๊ทผ์ ํ์ฉํด์ผ ํฉ๋๋ค. ์ถ๊ฐ๋ก ':0'์ ์๋ฏธ๋ ๋์คํ๋ ์ด ํฌํธ๋ฅผ ์๋ฏธํฉ๋๋ค.
์ดํ ํด๋น docker-compose.yml ๋ฅผ ๋ฐํ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ๋ง๋ค์ด ํด๋น ์ปจํ ์ด๋๋ฅผ ๋์์ค๋๋ค.
% docker-compose build
% docker-compose up -d
% docker-compose exec --user root ros2 bash
์ดํ ํด๋น ์ปจํ ์ด๋ ๋ด๋ถ์์ x11-apps ํจํค์ง ๋ด๋ถ์ ์๋ xclock์ ์คํ์ํค๋ฉด ์๊ณ๊ฐ ๋จ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
$ xclock
์ฐธ๊ณ
- [blog] How to Set Up and Use X11 Forwarding on Linux and Mac: https://www.businessnewsdaily.com/11035-how-to-use-x11-forwarding.html
- [Official]XQuartz: https://www.xquartz.org/index.html
- [Github] X11 forwarding on macOS and docker: https://gist.github.com/sorny/969fe55d85c9b0035b0109a31cbcb088
- [StackOverFlow] X11 forwarding of a GUI app running in docker: https://stackoverflow.com/questions/44429394/x11-forwarding-of-a-gui-app-running-in-docker
- [Blog] X11 ํฌ์๋ฉ ํ๊ธฐ (macOS): https://blog.naver.com/PostView.naver?blogId=chcbaram&logNo=222920381690&categoryNo=0&parentCategoryNo=0&viewDate=¤tPage=1&postListTopCurrentPage=1&from=postView
- [Blog] How to install X Window System XQuartz on macOS for ssh X11 forwarding: https://www.cyberciti.biz/faq/apple-osx-mountain-lion-mavericks-install-xquartz-server/