开发环境-Docker部署
一、Docker安装
1、安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
2、验证
sudo docker run hello-world
3、设置权限
sudo usermod -aG docker your-user(将-user替换为用户名)
二、导入开发环境
加载镜像
sudo docker load --input l3plus-ubuntu18.04-cuda10.0.img
查看已导入镜像
hagan@hagan-Latitude:~$ docker images -a
输出:
REPOSITORY TAG IMAGE ID CREATED SIZE
l3plus ubuntu18.04-cuda10.0 82687ee88af5 42 minutes ago 16.6GB
使用镜像生成容器
步骤说明:相当于在下载了iso镜像后,创建虚拟机
期间配置相关共享目录和环境变量以实现与宿主机共享显示
-p: 端口映射;
-d: 后台运行容器;
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
**–volume , -v: ** 绑定一个卷
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-w: 指定工作目录
-v: 挂载数据卷
-e: 设置env
sudo docker run --privileged=true -p 6080:80 -p 5900:5900 -d -it -w /root/l3plus -v /etc/localtime:/etc/localtime:ro -v /tmp/.X11-unix:/tmp/.X11-unix -v /home/$USER:/root/data/$USER -e RESOLUTION=1920x1080 -e DISPLAY=unix$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE l3plus:ubuntu18.04-cuda10.0 /bin/bash
启动容器
$ docker ps -a
输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55f7ccd8dff1 l3plus:ubuntu18.04-cuda10.0 "/bin/bash" 3 weeks ago Up 5 days 0.0.0.0:5900->5900/tcp, 0.0.0.0:6080->80/tcp zen_buck
--------------------------------------------------
hagan@hagan-Latitude:~$ docker start 55f7ccd8dff1
输出:
55f7ccd8dff1
创建容器终端
hagan@hagan-Latitude:~$ docker exec -it 55f7ccd8dff1 bash
输出:
root@55f7ccd8dff1:/#
三、共享显示
在宿主机新建终端并运行以下指令
sudo apt-get install x11-xserver-utils
xhost +
2、在Docker容器终端上输入
xarclock
四、docker l3plus 快速启动
设置l3plus环境变量
root@55f7ccd8dff1:/# cd /root/l3plus/ && colcon build && source install/setup.bash
l3plus 启动
root@55f7ccd8dff1:~/l3plus# ros2 launch quickstart quickstart.launch.py
五、docker其他使用
导入已有镜像
hagan@hagan-Latitude:~$ cat dftc_l3_env.tar | docker import - dftc_l3_env:base
输出:
sha256:162c629159aa150e2765f1b9e68773d0450fc142923c149ba3db0a53a61146bc
查看容器
hagan@hagan-Latitude:~$ docker ps -a
输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55f7ccd8dff1 dftc_l3_env:base "/bin/bash" 3 weeks ago Up 5 days 0.0.0.0:5900->5900/tcp, 0.0.0.0:6080->80/tcp zen_buck
退出容器终端
root@55f7ccd8dff1:~# exit
删除镜像
hagan@hagan-Latitude:~$ docker rmi dc4fd3f815e6
删除容器
hagan@hagan-Latitude:~$ docker stop 55f7ccd8dff1 && docker rm 55f7ccd8dff1
拷贝文件到docker:在宿主机新建终端并运行以下指令,将l3plus.tar.gz文件拷贝到docker的/root目录下
docker cp l3plus.tar.gz 55f7ccd8dff1:root
docker文件拷贝到主机:在宿主机新建终端并运行以下指令,将docker的/root目录下的l3plus.tar.gz文件拷贝到主机的home目录下
docker cp 55f7ccd8dff1:/root/l3plus.tar.gz /home/
将容器存储为镜像
$ sudo docker commit -m <说明> -a <作者> <当前运行的container id> <仓库名称>:<tag>
$ sudo docker save -o <仓库名称>-<tag>.img <仓库名称>:<tag>
$ sudo docker commit -m "l3plus-ubuntu18.04-cuda10.0-pythorch1.4.0-tensorflow_gpu-2.3.0" -a "hegaozhi" 55f7ccd8dff1 l3plus:ubuntu18.04-cuda10.0
$ docker images -a
输出
REPOSITORY TAG IMAGE ID CREATED SIZE
l3plus ubuntu18.04-cuda10.0 82687ee88af5 39 minutes ago 16.6GB
将镜像存储为本地文件
sudo docker save -o l3plus-ubuntu18.04-cuda10.0.img l3plus:ubuntu18.04-cuda10.0
docker内 l3plus 环境部署
#/bin/bash
cp -a etc / -r
service udev reload
sleep 2
service udev restart
apt-get update
apt-get install zip -y
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com F42ED6FBAB17C654
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com F60F4B3D7FA2AF80
apt-get update
apt-get upgrade
apt install build-essential -y
apt install libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev -y
apt install zlib1g-dev zip -y
apt install wget -y
apt install openssl vim -y
apt install curl git -y
apt install libsqlite3-dev -y
# wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
# tar -xvf Python-3.6.9.tgz
# cd Python-3.6.9
# ./configure --enable-loadable-sqlite-extensions --enable-shared CFLAGS=-fPIC
# make
# make install
# apt-get clean
# rm -rf /var/lib/apt/lists/*
# ln -s /usr/local/bin/pip3 /usr/bin/pip
# ln -s /usr/local/bin/python3 /usr/bin/python
pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
apt install libpcl-dev pcl-tools -y
apt install libpcap-dev libyaml-cpp-dev libyaml-dev -y
apt install libgoogle-glog-dev -y
pip3 install config -i https://pypi.tuna.tsinghua.edu.cn/simple
# ros2
locale-gen en_US en_US.UTF-8
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
apt update && apt install curl gnupg2 lsb-release
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
sh -c 'echo "deb http://mirror.tuna.tsinghua.edu.cn/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
apt install ros-dashing-desktop -y
apt install libasio-dev ros-dashing-diagnostic-updater -y
apt install ros-dashing-rosbag2-test-common ros-dashing-sqlite3-vendor ros-dashing-rosbag2-storage ros-dashing-rosbag2-storage-default-plugins ros-dashing-ros2bag -y
pip3 --default-timeout=100 install --upgrade setuptools pandas
pip3 --default-timeout=100 install -i https://pypi.tuna.tsinghua.edu.cn/simple Cython matplotlib>=2.1.1 numpy>=1.13.3 opencv-python>=3.4.6 PyYAML pillow pandas glog scipy
pip3 --default-timeout=100 install -i https://pypi.tuna.tsinghua.edu.cn/simple easydict opencv-python numpy scikit-learn catkin_pkg empy lark shapely tqdm mayavi
pip3 --default-timeout=100 install -i https://pypi.tuna.tsinghua.edu.cn/simple joblib==0.10.3 Pillow==4.0.0 tensorflow-gpu==1.15.4 -y
pip3 --default-timeout=100 install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
apt install python3-colcon-common-extensions -y
apt install libcanberra-gtk-module libopencv-dev -y
apt install python-catkin-tools -y