4. Docker hardware interaction and data processing4.1. Hardware mounting (port binding)4.2. Display of GUI in docker4.3. Transfer files between docker container and host machine4.3.1. Use cp naming4.3.1.1. Copy files from the container to the host4.3.1.2. Copy files from the host to the container
The operating environment and software and hardware reference configuration are as follows:
Reference model: ROSMASTER X3
Robot hardware configuration: Arm series main control, Silan A1 lidar, AstraPro Plus depth camera
Robot system: Ubuntu (no version required) + docker (version 20.10.21 and above)
PC virtual machine: Ubuntu (18.04) + ROS (Melodic)
Usage scenario: Use on a relatively clean 2D plane
Establish udev rules (/etc/udev/rules.d/) in the host machine, see chapter [6. Linux operating system ---- 6. Bind device ID]
Then when opening the container, mount the devices with the rules set into the docker container through --device=/dev/myserial --device=/dev/rplidar and other parameters.
xxxxxxxxxxdocker run -it --device=/dev/myserial --device=/dev/rplidar ubuntu:latest /bin/bash
The device can be found in the docker container
xxxxxxxxxxjetson@ubuntu:~$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEubuntu 1.0 78ca7be949b6 About an hour ago 69.2MBpengan88/ubuntu 1.0 78ca7be949b6 About an hour ago 69.2MByahboomtechnology/ros-foxy 3.4.0 49581aa78b6b 6 hours ago 24.3GByahboomtechnology/ros-foxy 3.3.9 cefb5ac2ca02 4 days ago 20.5GByahboomtechnology/ros-foxy 3.3.8 49996806c64a 4 days ago 20.5GByahboomtechnology/ros-foxy 3.3.7 8989b8860d17 5 days ago 17.1GByahboomtechnology/ros-foxy 3.3.6 326531363d6e 5 days ago 16.1GBmysql latest 5371f8c3b63e 6 days ago 592MBubuntu latest bab8ce5c00ca 6 weeks ago 69.2MBhello-world latest 46331d942d63 13 months ago 9.14kBjetson@ubuntu:~$ ll /dev | grep ttyUSB*lrwxrwxrwx 1 root root 7 Apr 23 18:07 myserial -> ttyUSB0lrwxrwxrwx 1 root root 7 Apr 23 18:07 rplidar -> ttyUSB1crwxrwxrwx 1 root dialout 188, 0 Apr 23 18:07 ttyUSB0crwxrwxrwx 1 root dialout 188, 1 Apr 23 18:07 ttyUSB1jetson@ubuntu:~$ docker run -it --device=/dev/myserial --device=/dev/rplidar ubuntu:latest /bin/bashroot@03522257ba30:/# ls /dev # There are already myserial and rplidar in dockerconsole fd full mqueue myserial null ptmx pts random rplidar shm stderr stdin stdout tty urandom zero
Install on the host machine:
xxxxxxxxxxsudo apt-get install tigervnc-standalone-server tigervnc-viewersudo apt-get install x11-xserver-utils
Execute in the host machine: xhost +
After the following picture is displayed normally, perform 3 steps:

Execute the command on the host to enter the container:
xxxxxxxxxxdocker run -it \ # Interactively run the docker image--env="DISPLAY" \ # Turn on the display GUI interface--env="QT_X11_NO_MITSHM=1" \ # Use X11 port 1 for display-v /tmp/.X11-unix:/tmp/.X11-unix \ # Map display service node directoryyahboomtechnology/ros-foxy:3.3.9 # The name of the image to be started/bin/bash # Execute the /bin/bash command within the containerTest
xxxxxxxxxxExecute in container: rviz2
xxxxxxxxxx# Orderdocker cp container id: path within the container destination host path
# test# Execute within the container and create a file testjetson@ubuntu:~$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc54bf9efae47 ubuntu:latest "/bin/bash" 2 hours ago Up 9 minutes funny_hugle3b9c01839579 hello-world "/hello" 3 hours ago Exited (0) 3 hours ago jovial_brownjetson@ubuntu:~$ docker attach c5root@c54bf9efae47:/# lsbin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr varroot@c54bf9efae47:/# cdroot@c54bf9efae47:~# lsroot@c54bf9efae47:~# touch test.txtroot@c54bf9efae47:~# lstest.txtroot@c54bf9efae47:~# pwd/rootroot@c54bf9efae47:/# read escape sequence #Press ctrl+P+Q to exit the container without stopping.jetson@ubuntu:~$ docker cp c54bf9efae47:/root/test.txt ~/jetson@ubuntu:~$ 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
xxxxxxxxxx# Orderdocker cp host file path container id: path within the container
#testjetson@ubuntu:~$ 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_brownjetson@ubuntu:~$ lsDesktop Documents Downloads fishros Music openvino Pictures Public rootOnNVMe run_docker.sh sensors snap temp Templates test.txt Videosjetson@ubuntu:~$ touch 11.txtjetson@ubuntu:~$ ls11.txt Desktop Documents Downloads fishros Music openvino Pictures Public rootOnNVMe run_docker.sh sensors snap temp Templates test.txt Videosjetson@ubuntu:~$ docker cp 11.txt c54bf9efae47:/root/jetson@ubuntu:~$ docker attach c5root@c54bf9e