조건:
- Ubuntu 20.04 + ROS noetic
- 디바이스 접근
- 네트워크 통신
- GUI (RVIZ, Gazebo)
- 작업 공간 공유
1. 작업 디렉토리 생성
mkdir ~/ros_noetic_docker cd ~/ros_noetic_docker
2. 필요한 파일 생성
# Dockerfile 생성 touch Dockerfile # entrypoint.sh 생성 touch entrypoint.sh # run_container.sh 생성 touch run_container.sh
3. 파일구조
~/ros_noetic_docker/ ├── Dockerfile ├── entrypoint.sh └── run_container.sh
4. gedit Dockerfile
FROM osrf/ros:noetic-desktop-full
# 기본 도구 설치
RUN apt-get update && apt-get install -y \
vim \
wget \
git \
bash-completion \
build-essential \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
# ROS 환경 설정
RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
# 작업 디렉토리 설정
WORKDIR /workspace
# 컨테이너 진입점 설정
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
5. gedit entrypoint.sh
#!/bin/bash
# entrypoint.sh
# ROS 마스터 URI 설정 (호스트 네트워크 사용 시)
if [ -n "$ROS_MASTER_URI" ]; then
echo "export ROS_MASTER_URI=$ROS_MASTER_URI" >> ~/.bashrc
fi
if [ -n "$ROS_IP" ]; then
echo "export ROS_IP=$ROS_IP" >> ~/.bashrc
fi
# 진입점 실행
exec "$@"
6. gedit run_container.sh
#!/bin/bash
# run_container.sh
# X11 포워딩을 위한 설정
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
docker run -it \
--name ros_noetic \
--network host \
--privileged \
-v /dev:/dev \
-e DISPLAY=$DISPLAY \
-e XAUTHORITY=$XAUTH \
-v $XAUTH:$XAUTH \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/catkin_noetic:/workspace \
ros_noetic_image
7. 실행 권한 부여
chmod +x entrypoint.sh chmod +x run_container.sh
8. Catkin 작업공간 생성
# Catkin 작업공간 생성 mkdir -p ~/catkin_noetic/src cd ~/catkin_noetic
9. 도커 이미지 빌드 및 실행
# 이미지 빌드 cd ~/ros_noetic_docker docker build -t ros_noetic_image . # 컨테이너 실행 ./run_container.sh
10.컨테이너 내의 작업 공간 초기화
cd /workspace catkin_make echo "source /workspace/devel/setup.bash" >> ~/.bashrc source ~/.bashrc
11. 터틀봇 예제 실행
# ROS 버전 확인 rosversion -d # roscore 실행 roscore
12. 새터미널 열기
docker exec -it ros_noetic bash rosrun turtlesim turtlesim_node
아래와 같은 화면이 나오면 성공
13. 컨테이너 종료
# 컨테이너 종료 docker stop ros_noetic # 실행 중인 컨테이너 목록 확인 docker ps # 모든 컨테이너 목록 확인 (종료된 것 포함) docker ps -a # 다음 사용시 컨테이너 재시작 docker start ros_noetic # 재시작된 컨테이너에 접속 docker exec -it ros_noetic bash

コメント
コメントを投稿