Docker内使用rviz等图像化界面的详细教程

0.前言

docker没有图形化界面,经过调研,还是有些方法可以实现的。

如果满足图像化界面,那以后就可以大大减少在环境配置上的时间损耗,多做点别的事情。

项目限定环境为Ubuntu16.04+ROS_Kinect,因此文章将以这个环境为主进行记录,希望可以帮助到大家。

1.构建镜像

新建名为kinetic-desktop-full的文件夹,这个名称要和启动脚本的名称一致。

  • 创建Dockerfile并写入如下代码:
ARG from
  
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04  as glvnd
FROM osrf/ros:kinetic-desktop-full
  
COPY --from=glvnd /usr/local/lib/x86_64-linux-gnu /usr/local/lib/x86_64-linux-gnu
COPY --from=glvnd /usr/local/lib/i386-linux-gnu /usr/local/lib/i386-linux-gnu
  
#COPY 10_nvidia.json /usr/local/share/glvnd/egl_vendor.d/10_nvidia.json
  
RUN echo '/usr/local/lib/x86_64-linux-gnu' >> /etc/ld.so.conf.d/glvnd.conf && \
    echo '/usr/local/lib/i386-linux-gnu' >> /etc/ld.so.conf.d/glvnd.conf && \
    ldconfig
  
ENV LD_LIBRARY_PATH /usr/local/lib/x86_64-linux-gnu:/usr/local/lib/i386-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  
# nvidia-container-runtime
ENV NVIDIA_VISIBLE_DEVICES \
    ${NVIDIA_VISIBLE_DEVICES:-all}
ENV NVIDIA_DRIVER_CAPABILITIES \
    ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics
  
RUN apt-get update && \
    apt-get install -y \
    build-essential \
    libgl1-mesa-dev \
    libglew-dev \
    libsdl2-dev \
    libsdl2-image-dev \
    libglm-dev \
    libfreetype6-dev \
    libglfw3-dev \
    libglfw3 \
    libglu1-mesa-dev \
    freeglut3-dev \
    dbus \
  • 创建启动脚本:
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
    xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
    if [ ! -z "$xauth_list" ]
    then
        echo $xauth_list | xauth -f $XAUTH nmerge -
    else
        touch $XAUTH
    fi
    chmod a+r $XAUTH
fi
 
docker run -it \
    --env="DISPLAY=$DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    --env="XAUTHORITY=$XAUTH" \
    --volume="$XAUTH:$XAUTH" \
    --runtime=nvidia \
    kinetic-desktop-full \
    bash

2.编译并生成容器

  • 创建好以上两个脚本后,依次运行如下指令:
sudo su
cd kinetic-desktop-full/
docker build -t kinetic-desktop-full .
chmod a+x run_my_image.bash
./run_my_image.bash

3.启动多终端

  • 进入容器后启动多终端,操作如下:
docker ps -a #查看容器id
———————————————————————————————————————————————————————————————————————————————————
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
5466fcb1d754        ros:kinetic-robot   "/ros_entrypoint.sh …"   25 minutes ago      Up 25 minutes                           focused_stonebraker
———————————————————————————————————————————————————————————————————————————————————
docker exec -it 5466fcb1d754 /bin/bash  #在指定的容器内创建新的终端,互不影响

按如上操作可以启动若干个终端

4.遇到问题:

启动rviz后虽然可以正常启动显示,但是会提示

process 105: D-Bus library appears to be incorrectly set up; failed to read machine uuid: UUID file '/etc/machine-id' should contain a hex string of length 32, not length 0, with no other text

解决办法为:

进入docker容器后,启动ros前输入如下:

dbus-uuidgen > /etc/machine-id

dbus安装包已在构建images时安装,再次启动该问题即可解决。

 

5.参考:

1.http://wiki.ros.org/docker/Tutorials/Hardware%20Acceleration#nvidia-docker1

2.https://blog.csdn.net/zdegrh_2/article/details/102936547

你可能感兴趣的:(小技巧,docker)