使用DockerFile创建ROS环境(带有xfce和vnc可以访问桌面查看ROS的图形工具)

基于 consol/ubuntu-xfce-vnc的DockerFile

FROM consol/ubuntu-xfce-vnc

# 切换到root,root才有权限进行安装软件等操作
USER 0

# 替换桌面背景(Dockerfile同目录下有图片screen-4.jpg)
COPY ./screen-4.jpg  /headless/.config/bg_sakuli.png

# 编辑sources.list,使用国内软件源
# 根据自己需求安装一些linux工具,如ping、tftp
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
    sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y iputils-ping tftp lsb-core && \
    apt-get clean
    
# 安装ROS及其编译工具,配置ROS环境
# 安装turtlesim功能包
RUN sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list' && \
    apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 && \
    apt-get -y update && \
    apt-get -y install ros-kinetic-desktop-full --allow-unauthenticated && \
    apt-get -y install ros-kinetic-turtlesim --allow-unauthenticated && \
    echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc && \
    apt-get -y install python-rosinstall python-rosinstall-generator python-wstool build-essential libblas-dev liblapack-dev --allow-unauthenticated && \
    apt-get clean
    
# 在生成镜像之前切换回default
#USER 1000
# 添加docker用户并默认是使用docker用户密码也是docker
RUN apt-get update &&\
	apt-get -y install sudo
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
USER docker
CMD /bin/bash

在任意一文件夹创建文件Dockerfile并把上面内容拷贝进去

构建

在Dockerfile目录下执行(后面有点),构建时间较长可以要多次尝试

docker build -t kinetic-full-xfce-vnc-docker .

启动容器

sudo docker images
sudo docker run -it  --rm  -e VNC_RESOLUTION=1920x1080 -p 5901:5901 -p 6901:6901     kinetic-full-xfce-vnc-docker  /bin/bash

-e VNC_RESOLUTION=1920×1080指定了图形化界面的分辨率,-p 5901:5901 -p 6901:6901指定了容器端口与本地主机的端口号映射关系,可自行设定。

访问容器的桌面系统

1、使用VNC Viewer
2、使用浏览器
在浏览器输入

 http://172.17.0.2:6901/?password=vncpassword

效果如图
在这里插入图片描述

参考资料

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章