docker安装与使用

开发环境-Docker部署

开发环境-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 

附录A: sources_apt

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

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu bionic main
deb-src [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu bionic main

附录B:udev:rules.d

KERNEL=="ttyUSB[0-9]*", MODE="0666"

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9902", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9903", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9001", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9101", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9201", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9202", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9301", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="9302", GROUP="users", MODE="0666"

KERNEL=="ttyACM*", KERNELS=="3-2", ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a8", MODE:="0777", SYMLINK+="ttyUbloxGps"

附录C:vimrc

" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on
endif

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd		" Show (partial) command in status line.
"set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
"set smartcase		" Do smart case matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a		" Enable mouse usage (all modes)
" 语法高亮
set syntax=on
set go=             " 不要图形按钮  
"color asmanian2     " 设置背景主题  
"set ruler           " 显示标尺
set showcmd         " 输入的命令显示出来,看的清楚些
"set cmdheight=1     " 命令行(在状态行下)的高度,设置为1  
"set whichwrap+=<,>,h,l   " 允许backspace和光标键跨越行边界(不建议)  
"set scrolloff=3     " 光标移动到buffer的顶部和底部时保持3行距离  
set novisualbell    " 不要闪烁(不明白)  
autocmd InsertLeave * se nocul  " 用浅色高亮当前行  
" autocmd InsertEnter * se cul    " 用浅色高亮当前行
set laststatus=1    " 启动显示状态行(1),总是显示状态行(2)  
set foldenable      " 允许折叠  
set foldmethod=manual   " 手动折叠  
"set background=dark "背景使用黑色 

"代码补全 
set completeopt=preview,menu 
"允许插件  
filetype plugin on
"共享剪贴板  
set clipboard+=unnamed 
"从不备份  
set nobackup
"make 运行
:set makeprg=g++\ -Wall\ \ %


" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 在行和段开始处使用制表符
set smarttab
" 显示行号
set number
set nobackup               	"覆盖文件时不备份
set ruler                       "在右下角显示光标位置的状态行

" 历史记录数
set history=1000
"禁止生成临时文件
set nobackup
set noswapfile
"搜索逐字符高亮
set hlsearch
set incsearch
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
"set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头 
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" 
""定义函数SetTitle,自动插入文件头 
func SetTitle() 
    "如果文件类型为.sh文件 
    if &filetype == 'sh' 
        call setline(1,"\#########################################################################") 
        call append(line("."), "\# File Name: ".expand("%")) 
        call append(line(".")+1, "\# Author: ") 
        call append(line(".")+2, "\# mail: 1@163.com") 
        call append(line(".")+3, "\# Created Time: ".strftime("%c")) 
        call append(line(".")+4, "\#########################################################################") 
        call append(line(".")+5, "\#!/bin/bash") 
        call append(line(".")+6, "") 
    else 
        call setline(1, "/*************************************************************************") 
        call append(line("."), "    > File Name: ".expand("%")) 
        call append(line(".")+1, "    > Author: ") 
        call append(line(".")+2, "    > Mail: 1@163.com ") 
        call append(line(".")+3, "    > Created Time: ".strftime("%c")) 
        call append(line(".")+4, " ************************************************************************/") 
        call append(line(".")+5, "")
    endif
    if &filetype == 'cpp'
        call append(line(".")+6, "#include <iostream>")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif
    if &filetype == 'c'
        call append(line(".")+6, "#include <stdio.h>")
        call append(line(".")+7, "")
    endif
    "新建文件后,自动定位到文件末尾
    autocmd BufNewFile * normal G
endfunc 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

nmap <leader>w :w!<cr>
nmap <leader>f :find<cr>

" 映射全选+复制 ctrl+a
map <C-A> ggVGY
map! <C-A> <Esc>ggVGY
map <F12> gg=G
" 选中状态下 Ctrl+c 复制
vmap <C-c> "+y
"去空行  
nnoremap <F2> :g/^\s*$/d<CR> 
"比较文件  
nnoremap <C-F2> :vert diffsplit 
"新建标签  
map <M-F2> :tabnew<CR>  
"列出当前目录文件  
map <F3> :tabnew .<CR>  
"打开树状文件目录  
map <C-F3> \be  
"C,C++ 按F5编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "! ./%<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "! ./%<"
    elseif &filetype == 'java' 
        exec "!javac %" 
        exec "!java %<"
    elseif &filetype == 'sh'
        :!./%
    endif
endfunc
"C,C++的调试
map <F8> :call Rungdb()<CR>
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb ./%<"
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听雨听风眠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值