Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save KaushalkumarPatel/56b2dc7ad0450f982a68e9097a954128 to your computer and use it in GitHub Desktop.

Select an option

Save KaushalkumarPatel/56b2dc7ad0450f982a68e9097a954128 to your computer and use it in GitHub Desktop.
Dockerfile to install & run Yolov8 on ROS Noetic (including GPU compability)
FROM nvidia/cudagl:11.4.2-base-ubuntu20.04
ENV DEBIAN_FRONTEND=noninteractive
# 2. Minimal ros setup and locales configuration
RUN apt-get update && apt-get install -y --no-install-recommends \
    locales \
    lsb-release \
    git \
    python3-pip \
    && pip3 install --no-cache-dir ultralytics \
    && dpkg-reconfigure locales \
    && sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' \
    && apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 \
    && apt-get update && apt-get install -y --no-install-recommends \
    ros-noetic-desktop-full \
    python3-rosdep \
    ros-noetic-catkin \
    build-essential \
    cmake \
    && rosdep init && rosdep fix-permissions && rosdep update \
    && echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
# 3. Create catkin workspace
RUN mkdir -p /root/catkin_ws/src
WORKDIR /root/catkin_ws
# 4. Copy your yolov8 repo (which i assumed you have configured yolov8 with ros noetic) from the specified path to catkin_ws/src
COPY /path/to/your/ros_yolov8 /root/catkin_ws/src/ros_yolov8
# 5. Install ROS package dependencies
RUN /bin/bash -c ". /opt/ros/noetic/setup.bash; cd /root/catkin_ws/; catkin_make" \
    && apt-get clean
# Source the setup.bash automatically in future sessions
RUN echo "source /root/catkin_ws/devel/setup.bash" >> ~/.bashrc
# Build the Dockerfile (open a terminal and go to this Dockerfile location)
docker build -t nvidia_ros .
xhost + (to access GUIs from Docker to my Host pc)
# Start a terminal (run the image to create a container)
docker run -it --net=host --gpus all \    --env="NVIDIA_DRIVER_CAPABILITIES=all" \    --env="DISPLAY" \    --env="QT_X11_NO_MITSHM=1" \    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \    nvidia_ros \    bash
#build command for realsense camera (optional command to run image if you already have a image of Realsense Camera)
docker run -it --net=host --gpus=all -e DISPLAY=${DISPLAY} -e QT_X11_NO_MITSHM=1 -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v /dev:/dev --device-cgroup-rule "c 81:* rmw" --device-cgroup-rule "c 189:* rmw" -v /tmp/.docker.xauth:/tmp/.docker.xauth:rw realsense_ros bash
# Test GUI based tools (run from container terminal itself)
rqt
gazebo
roscore & rviz 
# Check CUDA functionality (run from container terminal itself)
nvidia-smi 
# Check OpenGL functionality (run from container terminal itself)
apt-get install mesa-utils
glxgears
# Command to open rviZ (run from container terminal itself)
export LIBGL_ALWAYS_SOFTWARE=1rviz
(This will only apply to the current terminal session. Once you close the terminal or start a new session, the setting will be lost, and you'll need to set it again.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment