Welcome to Raspbot V2 repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
4. Docker data processing
4. Docker data processing
4. Docker data processing4.1. Display of GUI in docker4.2. Transfer files between docker container and host4.2.1. Naming with cp4.2.1.1. Copy files from the container to the host4.2.1.2, copy files from the host to the container4.2.2, Use data volume4.2.2.1, Overview of data volume4.2.2.2. Use of data volumes
4.1. Display of GUI in docker
Note: The factory image has been installed, no need to install again
- Install in the host:
xxxxxxxxxxsudo apt-get install tigervnc-standalone-server tigervnc-viewersudo apt-get install x11-xserver-utils
- Execute in the host: xhost +
After the following figure is displayed normally, perform 3 steps:

- Execute the command in the host to enter the container:
xxxxxxxxxxdocker run -it \ # Interactively run docker image--env="DISPLAY" \ # Enable the display of GUI interface--env="QT_X11_NO_MITSHM=1" \ # Use X11 port 1 for display-v /tmp/.X11-unix:/tmp/.X11-unix \ # Mapping shows the service node directoryyahboomtechnology/ros-humble:0.1.0 # The image name to be started/bin/bash # Execute the /bin/bash command in the container
- Test
xxxxxxxxxxExecute in the container: rviz2
4.2. Transfer files between docker container and host
4.2.1. Naming with cp
4.2.1.1. Copy files from the container to the host
xxxxxxxxxx# Commanddocker cp container id: path in container destination host path# Test# Execute in the container, create a file testpi@yahboom:~$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc54bf9efae47 ubuntu:latest "/bin/bash" 2 hours ago Up 9 minutes funny_hugle 3b9c01839579 hello-world "/hello" 3 hours ago Exited (0) 3 hours ago jovial_brown pi@yahboom:~$ docker attach c5 root@c54bf9efae47:/# ls bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var root@c54bf9efae47 :/# cd root@c54bf9efae47:~# ls root@c54bf9efae47:~# touch test.txt root@c54bf9efae47:~# ls test.txt root@c54bf9efae47:~# pwd /root root@c54bf9efae47:/# read escape sequence #Press ctrl+P+Q The container does not stop and exitpi@yahboom:~$ docker cp c54bf9efae47:/root/test.txt ~/pi@yahboom:~$ ls # The test.txt file has been copied inDesktop Documents Downloads fishros Music openvino Pictures Public rootOnNVMe run_docker.sh sensors snap temp Templates test.txt Videos
4.2.1.2, copy files from the host to the container
xxxxxxxxxx# Commanddocker cp host file path container id: path in the container# testpi@yahboom:~$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc54bf9efae47 ubuntu:latest "/bin/bash" 2 hours ago Up 5 minutes funny_hugle3b9c01839579 hello-world "/hello" 3 hours ago Exited (0) 3 hours ago jovial_brown pi@yahboom:~$ ls Desktop Documents Downloads fishros Music openvino Pictures Public rootOnNVMe run_docker.sh sensors snap temp Templates test.txt Videos pi@yahboom:~$ touch 11.txt pi@yahboom:~$ ls 11.txt Desktop Documents Downloads fishros Music openvino Pictures Public rootOnNVMe run_docker.sh sensors snap temp Templates test.txt Videos pi@yahboom:~$ docker cp 11.txt c54bf9efae47:/root/ pi@yahboom:~$ docker attach c5 root@c54bf9efae47:/# ls bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr varroot@c54bf9efae47:/# cd /root/root@c54bf9efae47:~# ls # 11.txt file has been copied11.txt test.txt
4.2.2, Use data volume
4.2.2.1, Overview of data volume
Package the application and the running environment into a container to run. The operation can be accompanied by the container, but our requirement for data is that it can be persistent! For example, if you install a mysql, but you delete the container, it is equivalent to deleting the library and running away, which is definitely not okay! So we hope that it is possible to share data between containers. If the data generated by the docker container is not generated through docker commit, so that the data is saved as part of the image, then when the container is deleted, the data will naturally disappear! This will not work!
In order to save data in docker, we can use volumes! Let the data be mounted locally! In this way, the data will not be lost due to container deletion!
Features:
- Data volumes can share or reuse data between containers
- Changes in volumes can take effect directly
- Changes in data volumes will not be included in image updates
- The life cycle of a data volume lasts until no container uses it
4.2.2.2. Use of data volumes
x# Commanddocker run -it -v host absolute path directory: container directory image name# Testdocker run -it -v /home/pi/temp:/root/temp yahboomtechnology/ros-humble:0.0.6 /bin/bashThe /home/jetson/temp directory in the host and the /root/temp directory in the container can share data