基於 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
效果如圖