本文主要根据Docker — 从入门到实践这个教程进行学习。
docker是一个进行机器人相关开发与测试的理想环境,而且Nvidia也推出了可以利用GPU的docker镜像,具体的安装指令如下:
docker run -it -d -P \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$DISPLAY \
--name robot \
--mount type=bind,source=/home/robotsky/docker-vol/robot-vol,target=/home/ \
nvidia/cuda:11.8.0-devel-ubuntu20.04 /bin/bash
为了可以运行可视化的程序,比如rviz,需要在宿主系统(Ubuntu 22.04)中运行xhost +si:localuser:root
指令,安装mesa-utils库后,就可以运行glxgears
来运行带有GUI界面的程序了。
Update:
经过学习后,又配置了dockerfile来编译镜像,可以替换Isaac Gym里面的dockerfile来编译含有ros的镜像:
FROM nvcr.io/nvidia/pytorch:20.12-py3
ENV DEBIAN_FRONTEND=noninteractive
# dependencies for gym and ros
#
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libxcursor-dev \
libxrandr-dev \
libxinerama-dev \
libxi-dev \
mesa-common-dev \
zip \
unzip \
make \
gcc-8 \
g++-8 \
vulkan-utils \
mesa-vulkan-drivers \
pigz \
git \
libegl1 \
git-lfs
# install ros1 and ros2
RUN apt install curl gnupg2 sudo neofetch -y \
&& echo "deb [arch=$(dpkg --print-architecture)] http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/ $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null \
&& curl -s https://gitee.com/ohhuo/rosdistro/raw/master/ros.asc | apt-key add - \
&& apt update \
&& apt install ros-foxy-desktop python3-argcomplete -y \
&& sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $(. /etc/os-release && echo $UBUNTU_CODENAME) main" > /etc/apt/sources.list.d/ros1.list' \
&& apt update \
&& apt install ros-noetic-desktop -y \
&& apt clean
# Force gcc 8 to avoid CUDA 10 build issues on newer base OS
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8
# WAR for eglReleaseThread shutdown crash in libEGL_mesa.so.0 (ensure it's never detected/loaded)
# Can't remove package libegl-mesa0 directly (because of libegl1 which we need)
RUN rm /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0 /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0.0.0 /usr/share/glvnd/egl_vendor.d/50_mesa.json
COPY docker/nvidia_icd.json /usr/share/vulkan/icd.d/nvidia_icd.json
COPY docker/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json
WORKDIR /opt/isaacgym
RUN useradd --create-home --no-log-init --shell /bin/bash gymuser \
&& adduser gymuser sudo \
&& echo 'gymuser:123456' | chpasswd
USER gymuser
# copy gym repo to docker
COPY --chown=gymuser . .
# install gym modules
ENV PATH="/home/gymuser/.local/bin:$PATH"
RUN mkdir /home/gymuser/robot \
&& cd python \
&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -q -e .
ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all