Ubuntu安装 Docker CE,VNC访问docker图形界面并安装ROS

从包安装

如果您无法使用Docker的存储库来安装Docker CE,则可以下载.deb适用于您的发行版的 文件并手动安装。每次要升级Docker CE时都需要下载新文件。

转到https://download.docker.com/linux/ubuntu/dists/,选择你的Ubuntu版本,浏览pool/stable/和选择amd64, armhfppc64el,或s390x

下载.deb要安装的Docker版本的文件:

树莓派3B+ Ubuntu mate

 wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/armhf/docker-ce_17.03.2~ce-0~ubuntu-xenial_armhf.deb

虚拟机Ubuntu 16.04

wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_17.03.3~ce-0~ubuntu-xenial_amd64.deb
  1. 安装Docker CE,将下面的路径更改为您下载Docker软件包的路径。

    sudo dpkg -i /path/to/package.deb

  2. Docker守护程序自动启动。

  3. 通过运行hello-world 映像验证是否正确安装了Docker CE 。

     sudo docker run hello-world

     

  4. 此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条信息性消息并退出。

Docker CE已安装并正在运行。该docker组已创建,但未向其添加任何用户。您需要使用它sudo来运行Docker命令。继续执行Linux的安装后步骤,以允许非特权用户运行Docker命令和其他可选配置步骤。

 

docker下载ros镜像:

虚拟机Ubuntu16.04

sudo docker pull ros:kinetic-perception-xenial

xenial: Ubuntu 16.04 VNC图形桌面不含ros

sudo docker pull dorowu/ubuntu-desktop-lxde-vnc:xenial

xenial: Ubuntu 16.04 VNC图形桌面已安装ros

sudo docker push jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

树莓派3B+ ros测试

sudo docker pull ros:kinetic-perception-xenial

运行镜像:

sudo docker run -it --privileged --device /dev/vchiq --device /dev/video0 --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" ros:kinetic-perception-xenial

 

运行docker容器并使用端口访问 6080

 sudo docker run -it --rm -p 6080:80 dorowu/ubuntu-desktop-lxde-vnc:xenial

浏览http://127.0.0.1:6080/

 

VNC查看器

将VNC服务端口5900转发给主机

sudo docker run -p 9080:80 -p 5900:5900 jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

现在,打开vnc查看器并连接到端口5900.如果您想通过密码保护vnc服务,请设置环境变量VNC_PASSWORD,例如

sudo docker run -p 9080:80 -p 5900:5900 -e VNC_PASSWORD=jyh654321 jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

需要用到USB硬件设备,如Kinect,摄像头

sudo docker run --privileged --device /dev/vchi --device /dev/video0 -p 7080:80 -p 5901:5900 jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

 

注意,在虚拟机容器桌面复制命令需要,先复制到粘贴板,再右击粘贴,才能把命令发送到容器内;

在虚拟机 容器1338e4261c4d   dorowu/ubuntu-desktop-lxde-vnc:xenial里安装ROS;

ros环境搭建-ubuntu16.04系统安装ROS Kinetic

https://blog.csdn.net/jacka654321/article/details/83015542

测试:

roscore

后台运行:

启动roscore后,在同一个终端窗口,输入:

nohup roscore &
nohup rosrun turtlesim turtlesim_node &

你还看到一只萌萌的海龟出现在屏幕上,那么该怎么样来操纵这只小海龟呢?不需要重新打开新的一个终端,直接输入即可:

 rosrun turtlesim  turtle_teleop_key 

 

 启动 rviz

nohup roscore & 
rviz

 

安装ROS-Academy-for-Beginners教学包

然后在创建一个名为tutorial_ws的工作空间,在它的的src路径下克隆ROS-Academy-for-Beginners软件包

mkdir -p tutorial_ws/src   
cd tutorial_ws/src        
git clone https://github.com/DroidAITech/ROS-Academy-for-Beginners.git

安装依赖

并且安装ROS-Academy-for-Beginners所需要的依赖

cd ~/tutorial_ws
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y

注意:以上命令非常重要,缺少依赖将导致软件包无法正常编译和运行。

在开始编译之前,需要确保Gazebo在7.0版本以上

gazebo -v

如果你的Gazebo版本低于7.0,则需要进行升级

sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install gazebo7

编译

接着回到catkin_ws下编译

cd ~/tutorial_ws
catkin_make
source ~/tutorial_ws/devel/setup.bash   #刷新环境 方法一
rospack profile #刷新环境 方法二

注意:source命令,编译完成后必须刷新一下工作空间的环境,否则可能找不到工作空间。许多时候我们为了打开终端就能够运行工作空间中编译好的ROS程序,我们习惯把source ~/tutorial_ws/devel/setup.bash命令追加到~/.bashrc文件中(rosacademy_ws替换为你的工作空间名称),这样每次打开终端,系统就会刷新工作空间环境。你可以通过echo "source ~/tutorial_ws/devel/setup.bash" >> ~/.bashrc命令来追加。

运行仿真程序

编译完成后就可以运行本教学配套的仿真了,输入

source ~/tutorial_ws/devel/setup.bash
rospack profile
roslaunch robot_sim_demo robot_spawn.launch

 

 

打开一个新的终端,输入以下命令,用键盘控制机器人移动

source ~/tutorial_ws/devel/setup.bash
rospack profile
rosrun robot_sim_demo robot_keyboard_teleop.py

聚焦控制程序窗口,按下i、j、l等按键,这样你就可以通过键盘来控制机器人的移动了。

过程图如下,记得运行前要刷新环境,或者用上面的方法把刷新命令添加到脚本;不然出报错robot_sim_demo not found;

刚开启时,云会动;

启动键盘控制后,

转向控制键:

yui

jkl

m,.

速度控制键:

qwe

zxc

 

局域网访问,本例nat方式,只能在虚拟机内打开,设置 桥接,可在宿主浏览器(局域网内)访问;

虚拟机设置frp,可实现外网访问;

https://blog.csdn.net/jacka654321/article/details/80879018

 

在虚拟机宿主,把容器打包成镜像:

sudo docker commit -m="xenial VNC ROS" -a="jacka654321" 1338e4261c4d  jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

上传至你的dockerhub:

sudo docker login

发布镜像 :
将您的标记镜像上传到存储库: 
docker push username/repository:tag

sudo docker push jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

感兴趣可以下载体验一下:

sudo docker pull jacka654321/ubuntu-desktop-lxde-vnc:xenial-ros

虚拟机Ubuntu系统里下载,

sudo docker pull osrf/gazebo:gzweb8

运行

sudo docker run -it --privileged --device /dev/vchiq --device /dev/video0 --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -v="/tmp/.gazebo/:/root/.gazebo/" --name=gazebo8 osrf/gazebo:gzweb8

虚拟机Ubuntu系统部署示例

在这个简短的例子中,我们将启动一个运行gazebo服务器的新容器,使用本地gazebo客户端连接到它,然后产生一个双倒立摆并记录模拟以供以后回放。

首先启动一个带安装卷的gazebo服务器进行日志记录并命名容器gazebo:

docker run -d -v="/tmp/.gazebo/:/root/.gazebo/" --name=gazebo osrf/gazebo:gzweb8

现在使用相同的入口点在容器中打开一个新的bash会话来配置环境。然后下载double_pendulum模型并将其加载到模拟中。

sudo docker exec -it 75f2ecd7afa4 bash

进入容器后需要更换源:

备份原来的源

sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

将以前的源备份一下,以防以后可以用的。

更换源

sudo gedit /etc/apt/sources.list

将下面所有内容复制,粘贴并覆盖sources.list文件中的所有内容; 

阿里云

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted #Added by software-properties

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial multiverse universe #Added by software-properties
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse restricted universe main #Added by software-properties
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse restricted universe main #Added by software-properties
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

清华源

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

 

如果容器内没有gedit nano vi等文本编辑工具,需要从宿主复制过去;

 sudo docker cp /etc/apt/sources.list 75f2ecd7afa4:/etc/apt/sources.list
 sudo docker cp /etc/apt/sources.list 1338e4261c4d:/etc/apt/sources.list

 让更新源生效

sudo apt-get update

配置环境

apt-get update && apt-get install -y curl 
curl -o double_pendulum.sdf http://models.gazebosim.org/double_pendulum_with_base/model-1_4.sdf 
gz model --model-name double_pendulum --spawn-file double_pendulum.sdf

要开始记录正在运行的模拟,只需使用gz log即可。

gz log --record 1

几秒钟后,通过禁用相同的标志继续并停止录制。

gz log --record 0

为了反省我们记录的记录,我们可以导航到日志目录并用于gz log打开和检查钟摆的运动和关节状态。这将允许您逐步摆过摆链的姿势。

cd ~/.gazebo/log/*/gzserver/
gz log --step --hz 10 --filter *.pose/*.pose --file state.log

如果您在本地安装了等效的Gazebo版本,则可以使用gzclient GUI连接到容器内的gzserver,方法是将主URI的地址设置为容器公共地址。

export GAZEBO_MASTER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' gazebo)
export GAZEBO_MASTER_URI=$GAZEBO_MASTER_IP:11345
gzclient --verbose

在使用gzclient渲染的OpenGL视图中,您应该看到先前仍在振荡的移动双摆。从这里,您可以使用图形界面控制或监控模拟状态,添加更多摆锤,重置世界,生成更多日志等。要退出模拟,请关闭gzclient窗口并停止容器。

docker stop gazebo
docker rm gazebo

即使我们的旧凉亭容器已被移除,我们仍然可以看到我们的记录日志已保留在主机卷目录中。

cd /tmp/.gazebo/log/
ls

同样,如果您在主机系统上安装了等效的Gazebo版本,则可以使用记录的日志文件使用Gazebo回放模拟。

export GAZEBO_MASTER_IP=127.0.0.1
export GAZEBO_MASTER_URI=$GAZEBO_MASTER_IP:11345
cd /tmp/.gazebo/log/*/gzserver/
gazebo --verbose --play state.log

使用教程:

https://hub.docker.com/_/gazebo/

 

参考链接:

通过VNC访问docker容器的图形界面

https://blog.csdn.net/spylyt/article/details/79944772

https://hub.docker.com/r/dorowu/ubuntu-desktop-lxde-vnc/

 

用于ARM和Debian的ROS Docker镜像

https://blog.csdn.net/ZhangRelay/article/details/77504626

https://github.com/osrf/docker_images

https://hub.docker.com/r/osrf/gazebo/

Ubuntu与ROS的Docker桌面系统与ROS在线练习课程(在线Linux虚拟机)

https://blog.csdn.net/ZhangRelay/article/details/73522385

https://www.shiyanlou.com/courses/63

ROS_安装一个第三方仿真软件包——机器人模拟世界

http://www.imooc.com/article/252345

阅读更多
换一批

没有更多推荐了,返回首页