본문 바로가기

카테고리 없음

mac에서 docker 이용 ros 설치법 (GUI 지원)

여기서는 Ros1 noetic을 기준으로 진행한다.

 

1. Docker 설치

https://docs.docker.com/desktop/install/mac-install/

 

Install on Mac

 

docs.docker.com

해당 링크에 들어가 dmg 파일을 열고 docker를 application 에 복사하면 된다. (mac을 처음 이용하는 사람을 위해.)

 

2. brew 설치 (이미 설치 되있을 경우 pass)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

https://brew.sh/

 

Homebrew

The Missing Package Manager for macOS (or Linux).

brew.sh

3. XQuartz 설치 및 세팅

xquartz 를 아래 명령어로 설치한다.

brew install xquartz

Xquartz를 실행한다.

open -a XQuartz

반드시, 설정에서 [보안] - 네트워크 클라이언트에서의 연결을 허용 체크 해주어야 한다.

XQuartz를 종료하고 terminal에서 아래 명령어를 이용해 XQuartz를 실행한다.

/opt/X11/bin/Xquartz :0 -listen tcp

 

IP, DISPLAY, 환경변수 설정 및 xhost를 PATH 환경변수에 추가한다.

IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
export DISPLAY=$IP:0
export PATH=/usr/X11/bin/xhost:$PATH
xhost + $IP

 

 

4. Docker container 생성 및 run

ubuntu focal 버전 image로 x11을 지원하며 ros_test2 라는 이름으로 container를 생성한다.

docker run -it --name ros_test2 -e DISPLAY=$IP:0 -v /tmp/.X11-unix:/tmp/.X11-unix ubuntu:focal /bin/bash

5. (docker 안에서) ros 설치를 위한 패키지를 설치해준다.

apt update
apt install -y lsb-core 
apt install -y software-properties-common wget sudo

6. (docker 안에서) one line installer로 ros noetic설치를 진행한다. 

wget -c https://raw.githubusercontent.com/qboticslabs/ros_install_noetic/master/ros_install_noetic.sh && chmod +x ./ros_install_noetic.sh && ./ros_install_noetic.sh

 

7. (docker 안에서) 튜토리얼에 있는 turtle예제를 위해 ros configuration을 진행한다. (본인 세팅이 있을 경우 별도 진행)

source /opt/ros/<distro>/setup.bash
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
source devel/setup.bash

 

8. (docker 안에서) roscore 실행

roscore

 

9. container에 연결된 다른 터미널 열기

(앞으로 ros 튜토리얼을 진행할 때 ros 환경에서 새 터미널을 열어야 하는경우 아래와 같이 열면된다.)

docker 바깥에서 다른 터미널을 열고 진행한다.

IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
docker exec -it -e DISPLAY=$IP:0 ros_test2 /bin/bash

10. (새로 연 docker 안에서) turtlesim node를 run한다.

source /opt/ros/noetic/setup.bash
cd ~/catkin_ws/
source devel/setup.bash
rosrun turtlesim turtlesim_node

 

 

출처 - https://affolter.net/running-a-docker-container-with-gui-on-mac-os/

http://wiki.ros.org/ROS/Tutorials