内容说明
镜像中已有环境:
- 容器只有root用户,密码为a
- 软件源为中科大源
- apt安装:tzdata、git、openssh-server、vim、zsh、silversearcher-ag、fzf、curl、tmux
- tzdata时区为上海
- git使用默认设置,未配置账号
- ssh端口为2222,允许root用户登录
- vim使用默认设置
- 安装了zsh、oh-my-zsh、powerlevel10k主题,并安装了插件(zsh-syntax-highlighting、zsh-autosuggestions、git、extract、ag)
- fzf使用默认设置(无法使用快捷键,想要使用快捷键需要apt remove --purge fzf,然后手动安装fzf
- tmux使用默认设置,同时安装了Oh my tmux,也是默认设置
- Ubuntu版本为22.04,ROS2版本为Humble
Dockerfile
FROM osrf/ros:humble-desktop-full RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \ && sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \ && apt update && apt upgrade -y && DEBIAN_FRONTEND=noninteractive \ apt install \ tzdata \ git \ openssh-server \ vim \ zsh \ silversearcher-ag \ fzf \ curl \ tmux \ -y \ && sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config \ && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \ && chsh -s /bin/zsh \ && sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended \ && sed -i '/^plugins=(git)$/c\plugins=(\n zsh-syntax-highlighting\n zsh-autosuggestions\n git\n extract\n ag\n)' ~/.zshrc \ && git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions \ && git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting \ && git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k \ && sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc \ && cd && git clone https://github.com/gpakosz/.tmux.git \ && ln -s -f .tmux/.tmux.conf \ && cp .tmux/.tmux.conf.local . \ && echo "source /opt/ros/humble/setup.zsh" >> ~/.zshrc \ && echo 'source /usr/share/colcon_cd/function/colcon_cd.sh' >> ~/.zshrc \ && echo 'export _colcon_cd_root=/opt/ros/humble/' >> ~/.zshrc \ && echo 'source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.zsh' >> ~/.zshrc \ && echo 'eval "$(register-python-argcomplete3 ros2)"' >> ~/.zshrc \ && echo 'eval "$(register-python-argcomplete3 colcon)"' >> ~/.zshrc
docker-compose.yaml
# 这个version指的是compose文档的官方版本,不同版本号所含的功能不同 # 具体见 https://docs.docker.com/compose/compose-file/compose-versioning/ # 编写本教程时的最新版本为3.8 version: '3.8' # 项目名称 name: development # 所有的容器的定义都要在services这个顶级元素下定义 services: # 服务名称,可以与项目名称保持一致 ros2humble: # 设置为true,则容器内PID为1的进程就会是docker提供的一个init程序 # 这样可以使容器能够回收内部的僵尸进程,避免占用资源 init: true # 容器名称,可以与项目名称保持一致 container_name: development-container-ros2humble # 实现docker run命令中-i参数的效果 stdin_open: true # 网络模式设置为host,就可以与主机使用同一个网络,而不是使用docker虚拟网卡的桥接网络,方便设置代理和ssh连接 network_mode: "host" # 设置为true,则容器内的root用户与主机的root用户具有相同的权限 privileged: true image: ubuntu:22.04_amd64_ros2humble # 设置容器启动后自动执行的命令,可以为空,为空则执行Dockerfile中指定的命令 # 容器内PID为1的进程退出后,容器就会关闭,为了防止容器自动关闭,就需要让容器一直运行程序 # tail -f /dev/null这个命令可以防止容器启动后自动退出,但因为前面设置了stdin_open,所以可以为空 # command: tail -f /dev/null command: bash -c "service ssh start && tail -f /dev/null" # 设置要挂载的目录,可以理解为共享文件夹 volumes: # 显示GUI所必须的 - "/tmp/.X11-unix:/tmp/.X11-unix:rw" # 使容器可以读取到外接设备 # 比如主机上插了一个USB相机,挂载/dev后,容器内就也可以使用该相机了 - "/dev:/dev:rw" # 将docker-compose.yaml所在目录下的SHARE文件夹(如果不存在则会自动创建一个)共享到容器中 # 目的是方便在容器和主机间共享数据 - "./SHARE:/root/SHARE:rw" # 设置容器的默认工作目录 working_dir: /root # 设置环境变量 environment: # 显示GUI所必须的 - DISPLAY=$DISPLAY # 显示GUI所必须的 - QT_X11_NO_MITSHM=1 # 设置语言环境 - LC_ALL=C.UTF-8
构建过程
- 清理所有的构建缓存(可选)
docker builder prune -a
- 构建镜像
- 执行构建
docker buildx build \ --builder=default \ --platform=linux/amd64 \ --tag=ubuntu:22.04_amd64_ros2humble \ --load .
- 启动容器
docker compose up -d
- 进入容器
docker exec -it development-container-ros2humble zsh
- zsh主题配置
y y y y 1 2 2 3 3 2 2 2 2 n 1 y
- 设置root用户密码为a
passwd
- 设置时区为Asia/Shanghai
dpkg-reconfigure tzdata
应该在6、70
- 删除apt缓存,缩减镜像体积(可选):Best practices for Dockerfile instructions | Docker Docs — Dockerfile 指令的最佳实践 | Docker 文档
apt clean && rm -rf /var/lib/apt/lists/*
- 清理命令历史记录
cat /dev/null > ~/.bash_history \ && cat /dev/null > ~/.zsh_history \ && history -c
按下Ctrl+D退出容器。
- 停止容器
docker stop development-container-ros2humble
- 直接保存为镜像(镜像为多层)
docker commit development-container-ros2humble ubuntu:22.04_amd64_ros2humble
- 或导出为tar包再导入为镜像(只有一层,镜像体积更小)
docker export development-container-ros2humble -o=ubuntu:22.04_amd64_ros2humble.tar
docker import ubuntu:22.04_amd64_ros2humble.tar ubuntu:22.04_amd64_ros2humble
- 或导出为tar包再导入为镜像(只有一层,镜像体积更小)
- 清理命令历史记录
- 删除apt缓存,缩减镜像体积(可选):Best practices for Dockerfile instructions | Docker Docs — Dockerfile 指令的最佳实践 | Docker 文档
- 设置时区为Asia/Shanghai
- 设置root用户密码为a
猜你喜欢
- 18天前(零碳中国·绿色投资蓝皮书)中国"零碳"差旅之路暨"绿色低碳酒店"标准研究项目成果发布会召开
- 18天前(2020海丝之路文化博览会)2023海丝之路文化和旅游博览会开幕
- 18天前(瑞虎7plus2021款)重塑10万级SUV价值标杆,全新一代瑞虎7PLUS冠军版给你惊喜
- 18天前(东北地区全域旅游)东北三省一区宣传贯彻研学旅游行业标准
- 18天前(河南省文旅大会精神)2025河南省文化旅游发展大会新闻发布会在郑州召开
- 18天前(花王伴你乐享五一好“趣”处)花王伴你乐享五一好“趣”处
- 18天前(辽宁新增6个国家4a级旅游景区有哪些)辽宁新增6个国家4A级旅游景区
- 18天前(大连aaaaa景区)辽宁大连A级旅游景区应急救护水平整体跃升
- 18天前(筑格集团有限公司)洲际酒店集团旗下筑格酒店品牌正式亮相大中华区
- 18天前(第三届“堡里有年味·回村过大年”民俗花灯会活动)第三届“堡里有年味·回村过大年”民俗花灯会活动
网友评论
- 搜索
- 最新文章
- (2020广州车展哈弗)你的猛龙 独一无二 哈弗猛龙广州车展闪耀登场
- (哈弗新能源suv2019款)智能科技颠覆出行体验 哈弗重塑新能源越野SUV价值认知
- (2021款全新哈弗h5自动四驱报价)新哈弗H5再赴保障之旅,无惧冰雪护航哈弗全民电四驱挑战赛
- (海南航空现况怎样)用一场直播找到市场扩张新渠道,海南航空做对了什么?
- (visa jcb 日本)优惠面面俱到 JCB信用卡邀您畅玩日本冰雪季
- (第三届“堡里有年味·回村过大年”民俗花灯会活动)第三届“堡里有年味·回村过大年”民俗花灯会活动
- (展示非遗魅力 长安启源助力铜梁龙舞出征)展示非遗魅力 长安启源助力铜梁龙舞出征
- (阿斯塔纳航空公司)阿斯塔纳航空机队飞机数量增至50架
- (北京香港航班动态查询)香港快运航空北京大兴新航线今日首航
- (我在港航“呵护”飞机 每一次安全着陆就是最好的荣誉)我在港航“呵护”飞机 每一次安全着陆就是最好的荣誉
- 热门文章