docker的使用记录(20201111)

it2024-12-27  14

使用docker file构建镜像

docker build -t ahren001/ros:20201117

使用容器及镜像的操作

ahren@ahren:~$ docker images #镜像列表 REPOSITORY TAG IMAGE ID CREATED SIZE ros v1.1 1ce4163432cc 20 hours ago 3.32GB ahren001/demo v1.0 854c47df3ea4 22 hours ago 2.21GB ros/demo v1.0 854c47df3ea4 22 hours ago 2.21GB ros 1021 8c9e71d89a91 26 hours ago 2.11GB ubuntu xenial 096efd74bb89 3 weeks ago 127MB candle mapping 9c20a7656a1f 3 weeks ago 7.14GB ctirobot/mapping cartographer_ros 1444adfe2590 4 weeks ago 6.73GB ahren@ahren:~$ docker run -it ahren001/demo:v1.0 #进入镜像 root@2108660433ee:/# ahren@ahren:~/script$ docker container ls #容器列表 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5ba61efc1193 ros:1104 "bash" 3 days ago Up 3 days cocky_goodall docker stop $(docker ps -a -q) #停止所有的容器 docker rm $(docker ps -a -q) #只删除单个时把后面的变量改为image id即可 docker rmi -f $(docker images -q) # -f强制删除images root@cti-KL35:/home/cti# docker cp 648e52f7fc18:/root/.ros/cloud_scheduling_node/cloud_scheduling_node.log ~/ root@cti-KL35:/home/cti# docker cp #容器-主机 optimistic_cray:/root/.ros/cloud_scheduling_node/cloud_scheduling_node.log ~/ root@cti-KL35:/home/cti# docker cp cloud_scheduling_node.log optimistic_cray:/root/.ros/cloud_scheduling_node/ #主机-容器

保存对容器的修改,存为镜像

docker ps #查看正在运行的容器 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9dfc41f9c866 ahren001/demo:v1.0 "bash" 29 minutes ago Up 29 minutes docker exec -it 9dfc41f9c866 bash #查看id,进入容器安装或卸载、cp等操作,修改完后exit退出容器 docker commit 3bd0eef03413 demo:v1.3 #提交你刚才修改的镜像,新的镜像名称为demo,版本为v1.3

docker镜像的备份与恢复

#备份 恢复tar docker export 680d9b254b0b > ros:1026.tar #导出,区分容器ID sudo docker import - ros:1758 < 1758.tar #导入 - 表示名字 #更换镜像的名称 docker tag 镜像id 镜像名字:版本号

docker与ros主机相互通信(网络/USB端口/挂载主机目录)

docker run -it --network=host ros:1026 bash #与本地主机网络通信 #挂载本地主机目录到容器 /data ahren@ahren:~$ docker run --name test102 -it -v /home/ahren:/data ros:1104 /bin/bash #启动容器增加特权参数 docker run --privileged -it \ #网络时间同步 -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro \ #挂载本地文件目录 -v /home/cti:/home \ #容器内访问宿主机硬件资源 -v /dev/front_lidar:/dev/front_lidar -v /dev/rear_lidar:/dev/rear_lidar \ -v /dev/rfid:/dev/rfid \ -v /dev/robot_base:/dev/robot_base \ -v /dev/ttyACM0:/dev/ttyACM0 \ -v /dev/ttyACM1:/dev/ttyACM1 \ -v /dev/v4l/by-id/usb-KINGSEN_KS2A418-60-video-index0:/dev/v4l/by-id/usb-KINGSEN_KS2A418-60-video-index0 \ #访问音频硬件 -v /dev/lora:/dev/lora \ #启动镜像名称 ros1126,伪终端 bash ros1112 bash root@cti-KL35:/# source /opt/cti/kinetic/setup.bash root@cti-KL35:/# roslaunch br_bringup start_br.launch

docker 镜像上传到docker hub

docker push 注册用户名/镜像名 #注意tag 镜像的时候,要加上自己docker hub 的用户名,我这里是ahren001 ahren@ahren:~/script$ docker push ahren001/ros:1029 The push refers to repository [docker.io/ahren001/ros] 74c4d73b45f0: Pushed 1029: digest: sha256:629feda27561313fa041ba6dead6489311de12f9a6e0723454dde33c3a79cd63 size: 531

 

最新回复(0)